mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-25 23:09:22 +00:00
Can get a friendship status
This commit is contained in:
parent
a78510d426
commit
ca2e106852
@ -60,6 +60,34 @@ export class FriendsController {
|
|||||||
h.send(this.FriendToAPI(info, true));
|
h.send(this.FriendToAPI(info, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a friendship status
|
||||||
|
*
|
||||||
|
* @param h Request handler
|
||||||
|
*/
|
||||||
|
public static async GetStatus(h: RequestHandler) {
|
||||||
|
const friendID = await h.postUserId("friendID");
|
||||||
|
|
||||||
|
let response = {
|
||||||
|
are_friend: false,
|
||||||
|
sent_request: false,
|
||||||
|
received_request: false,
|
||||||
|
following: false
|
||||||
|
}
|
||||||
|
|
||||||
|
response.are_friend = await FriendsHelper.AreFriend(h.getUserId(), friendID);
|
||||||
|
|
||||||
|
if(!response.are_friend) {
|
||||||
|
response.sent_request = await FriendsHelper.SentRequest(h.getUserId(), friendID);
|
||||||
|
response.received_request = await FriendsHelper.SentRequest(friendID, h.getUserId());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
response.following = await FriendsHelper.IsFollowing(h.getUserId(), friendID);
|
||||||
|
|
||||||
|
|
||||||
|
h.send(response);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turn a friend object into an API entry
|
* Turn a friend object into an API entry
|
||||||
*
|
*
|
||||||
|
@ -81,6 +81,8 @@ export const Routes : Route[] = [
|
|||||||
|
|
||||||
{path: "/friends/get_single_infos", cb: (h) => FriendsController.GetSingleFrienshipInfo(h)},
|
{path: "/friends/get_single_infos", cb: (h) => FriendsController.GetSingleFrienshipInfo(h)},
|
||||||
|
|
||||||
|
{path: "/friends/getStatus", cb: (h) => FriendsController.GetStatus(h)},
|
||||||
|
|
||||||
|
|
||||||
// Conversations controller
|
// Conversations controller
|
||||||
{path: "/conversations/create", cb: (h) => ConversationsController.CreateConversation(h)},
|
{path: "/conversations/create", cb: (h) => ConversationsController.CreateConversation(h)},
|
||||||
|
@ -80,6 +80,23 @@ export class FriendsHelper {
|
|||||||
return this.DbToFriend(result);
|
return this.DbToFriend(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check out whether a user sent a request to another friend
|
||||||
|
*
|
||||||
|
* @param userID The ID of the user supposed to have sent a request
|
||||||
|
* @param targetUser The ID of the target user
|
||||||
|
*/
|
||||||
|
public static async SentRequest(userID: number, targetUser: number) : Promise<boolean> {
|
||||||
|
return await DatabaseHelper.Count({
|
||||||
|
table: FRIENDS_TABLE,
|
||||||
|
where: {
|
||||||
|
ID_personne: targetUser,
|
||||||
|
ID_amis: userID,
|
||||||
|
actif: 0
|
||||||
|
}
|
||||||
|
}) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Count the number of friendship requests a user
|
* Count the number of friendship requests a user
|
||||||
* received
|
* received
|
||||||
|
Loading…
Reference in New Issue
Block a user