mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 05:19:22 +00:00
Return the number of friends of the user
This commit is contained in:
parent
a22f339a17
commit
d1ea274281
@ -4,6 +4,7 @@ import { User, UserPageStatus } from "../entities/User";
|
||||
import { AccountImage, AccountImageVisibilityLevel } from "../entities/AccountImage";
|
||||
import { BackgroundImageHelper } from "../helpers/BackgroundImageHelper";
|
||||
import { LikesHelper, LikesType } from "../helpers/LikesHelper";
|
||||
import { FriendsHelper } from "../helpers/FriendsHelper";
|
||||
|
||||
/**
|
||||
* User information controller
|
||||
@ -87,6 +88,7 @@ export class UserController {
|
||||
info["account_creation_time"] = user.timeCreate;
|
||||
info["backgroundImage"] = BackgroundImageHelper.GetURL(user.id);
|
||||
info["pageLikes"] = await LikesHelper.Count(user.id, LikesType.USER);
|
||||
info["number_friends"] = user.friendsListPublic ? await FriendsHelper.CountForUser(user.id) : 0
|
||||
}
|
||||
|
||||
return info;
|
||||
|
@ -26,6 +26,21 @@ export class FriendsHelper {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of friends of a specific user
|
||||
*
|
||||
* @param userID Target user ID
|
||||
*/
|
||||
public static async CountForUser(userID: number) : Promise<number> {
|
||||
return await DatabaseHelper.Count({
|
||||
table: FRIENDS_TABLE,
|
||||
where: {
|
||||
ID_amis: userID,
|
||||
actif: 1
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check out whether two users are friend or not
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user