1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 05:19:22 +00:00

Can remove a friend from the list

This commit is contained in:
Pierre HUBERT 2020-01-01 12:17:24 +01:00
parent eefba81fd3
commit f46d87def5
3 changed files with 35 additions and 0 deletions

View File

@ -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
*

View File

@ -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)},

View File

@ -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