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

Get information about a single friendship

This commit is contained in:
Pierre HUBERT 2019-12-31 10:08:04 +01:00
parent cf99c719bb
commit 2152511843
3 changed files with 56 additions and 0 deletions

View File

@ -44,6 +44,22 @@ export class FriendsController {
h.send(friends.map((f) => f.friendID)); h.send(friends.map((f) => f.friendID));
} }
/**
* Get single friendship information
*
* @param h Request handler
*/
public static async GetSingleFrienshipInfo(h: RequestHandler) {
const friendID = await h.postUserId("friendID");
const info = await FriendsHelper.GetSingleInfo(h.getUserId(), friendID);
if(info == null)
h.error(404, "Requested frienship not found!");
h.send(this.FriendToAPI(info, true));
}
/** /**
* Turn a friend object into an API entry * Turn a friend object into an API entry
* *

View File

@ -79,6 +79,8 @@ export const Routes : Route[] = [
{path: "/friends/get_user_list", cb: (h) => FriendsController.GetOtherUserList(h), needLogin: false}, {path: "/friends/get_user_list", cb: (h) => FriendsController.GetOtherUserList(h), needLogin: false},
{path: "/friends/get_single_infos", cb: (h) => FriendsController.GetSingleFrienshipInfo(h)},
// Conversations controller // Conversations controller
{path: "/conversations/create", cb: (h) => ConversationsController.CreateConversation(h)}, {path: "/conversations/create", cb: (h) => ConversationsController.CreateConversation(h)},

View File

@ -42,6 +42,44 @@ export class FriendsHelper {
return results.map((r) => this.DbToFriend(r)); return results.map((r) => this.DbToFriend(r));
} }
/**
* Get information about a single membership
*
* @param userID Target user ID (ID of the user making the request)
* @param friendID Target friend ID
* @returns Information about the membership / null if no membership was found
*/
public static async GetSingleInfo(userID: number, friendID: number) : Promise<Friend> {
// Same request has above, but just for a single user
const result = await DatabaseHelper.QueryRow({
table: FRIENDS_TABLE + " f",
where: {
ID_personne: userID,
ID_amis: friendID
},
joins: [
{
table: USER_TABLE + " u",
condition: "f.ID_amis = u.ID"
}
],
fields: [
"u.last_activity",
"f.ID_amis",
"f.actif",
"f.abonnement",
"f.autoriser_post_page"
],
order: "u.last_activity DESC"
});
if(result == null)
return null;
return this.DbToFriend(result);
}
/** /**
* Count the number of friendship requests a user * Count the number of friendship requests a user
* received * received