mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 13:29:22 +00:00
Can cancel a frienship request
This commit is contained in:
parent
f51a20f0e4
commit
d8bc8022c0
@ -115,6 +115,24 @@ export class FriendsController {
|
||||
h.success("Send (create) the friendship request");
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel (remove) a friendship request
|
||||
*
|
||||
* @param h Request handler
|
||||
*/
|
||||
public static async CancelRequest(h: RequestHandler) {
|
||||
const friendID = await h.postUserId("friendID");
|
||||
|
||||
if(!await FriendsHelper.SentRequest(h.getUserId(), friendID))
|
||||
h.error(401, "No friendship request was sent to this user!");
|
||||
|
||||
await FriendsHelper.RemoveRequest(h.getUserId(), friendID);
|
||||
|
||||
// TODO : delete any related notification
|
||||
|
||||
h.success("Friendship request removed!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a friend object into an API entry
|
||||
*
|
||||
|
@ -85,6 +85,8 @@ export const Routes : Route[] = [
|
||||
|
||||
{path: "/friends/sendRequest", cb: (h) => FriendsController.SendRequest(h)},
|
||||
|
||||
{path: "/friends/removeRequest", cb: (h) => FriendsController.CancelRequest(h)},
|
||||
|
||||
|
||||
// Conversations controller
|
||||
{path: "/conversations/create", cb: (h) => ConversationsController.CreateConversation(h)},
|
||||
|
@ -114,6 +114,23 @@ export class FriendsHelper {
|
||||
}) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a previously sent friendship request
|
||||
*
|
||||
* @param userID The ID of the user who have sent the request
|
||||
* @param targetUser The ID of the target user
|
||||
*/
|
||||
public static async RemoveRequest(userID: number, targetUser: number) {
|
||||
await DatabaseHelper.DeleteRows(
|
||||
FRIENDS_TABLE,
|
||||
{
|
||||
ID_personne: targetUser,
|
||||
ID_amis: userID,
|
||||
actif: 0
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of friendship requests a user
|
||||
* received
|
||||
|
Loading…
Reference in New Issue
Block a user