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

Return the number of friends of the user

This commit is contained in:
Pierre HUBERT 2019-12-28 14:09:20 +01:00
parent a22f339a17
commit d1ea274281
2 changed files with 17 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import { User, UserPageStatus } from "../entities/User";
import { AccountImage, AccountImageVisibilityLevel } from "../entities/AccountImage"; import { AccountImage, AccountImageVisibilityLevel } from "../entities/AccountImage";
import { BackgroundImageHelper } from "../helpers/BackgroundImageHelper"; import { BackgroundImageHelper } from "../helpers/BackgroundImageHelper";
import { LikesHelper, LikesType } from "../helpers/LikesHelper"; import { LikesHelper, LikesType } from "../helpers/LikesHelper";
import { FriendsHelper } from "../helpers/FriendsHelper";
/** /**
* User information controller * User information controller
@ -87,6 +88,7 @@ export class UserController {
info["account_creation_time"] = user.timeCreate; info["account_creation_time"] = user.timeCreate;
info["backgroundImage"] = BackgroundImageHelper.GetURL(user.id); info["backgroundImage"] = BackgroundImageHelper.GetURL(user.id);
info["pageLikes"] = await LikesHelper.Count(user.id, LikesType.USER); info["pageLikes"] = await LikesHelper.Count(user.id, LikesType.USER);
info["number_friends"] = user.friendsListPublic ? await FriendsHelper.CountForUser(user.id) : 0
} }
return info; return info;

View File

@ -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 * Check out whether two users are friend or not
* *