mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-12-28 14:38:52 +00:00
Can remove a friend from the list
This commit is contained in:
parent
eefba81fd3
commit
f46d87def5
@ -152,6 +152,21 @@ export class FriendsController {
|
||||
h.success("Response to the friendship request successfully saved!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a friend from the list
|
||||
*
|
||||
* @param h Request handler
|
||||
*/
|
||||
public static async RemoveFriend(h: RequestHandler) {
|
||||
const friendID = await h.postUserId("friendID");
|
||||
|
||||
await FriendsHelper.RemoveFriendship(h.getUserId(), friendID);
|
||||
|
||||
// TODO : delete any related notification
|
||||
|
||||
h.success("The friend was removed from the list!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a friend object into an API entry
|
||||
*
|
||||
|
@ -89,6 +89,8 @@ export const Routes : Route[] = [
|
||||
|
||||
{path: "/friends/respondRequest", cb: (h) => FriendsController.RespondRequest(h)},
|
||||
|
||||
{path: "/friends/remove", cb: (h) => FriendsController.RemoveFriend(h)},
|
||||
|
||||
|
||||
// Conversations controller
|
||||
{path: "/conversations/create", cb: (h) => ConversationsController.CreateConversation(h)},
|
||||
|
@ -161,6 +161,24 @@ export class FriendsHelper {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy a friendship
|
||||
*
|
||||
* @param userOne The ID of the first user
|
||||
* @param userTwo The ID of the second user
|
||||
*/
|
||||
public static async RemoveFriendship(userOne: number, userTwo: number) {
|
||||
await DatabaseHelper.DeleteRows(FRIENDS_TABLE, {
|
||||
ID_personne: userOne,
|
||||
ID_amis: userTwo
|
||||
});
|
||||
|
||||
await DatabaseHelper.DeleteRows(FRIENDS_TABLE, {
|
||||
ID_personne: userTwo,
|
||||
ID_amis: userOne
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of friendship requests a user
|
||||
* received
|
||||
|
Loading…
Reference in New Issue
Block a user