mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 21:39: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 { 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;
|
||||||
|
@ -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
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user