1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-26 07:19:23 +00:00

Completed advanced info

This commit is contained in:
Pierre HUBERT 2019-12-28 14:29:00 +01:00
parent d1ea274281
commit 92723b487a
3 changed files with 74 additions and 3 deletions

View File

@ -68,7 +68,7 @@ export class UserController {
} }
private static async UserToAPI(user : User, handler: RequestHandler, advanced: boolean = false) : Promise<Object> { private static async UserToAPI(user : User, h: RequestHandler, advanced: boolean = false) : Promise<Object> {
const info = { const info = {
"userID": user.id, "userID": user.id,
"firstName": user.firstName, "firstName": user.firstName,
@ -76,7 +76,7 @@ export class UserController {
"publicPage": user.pageStatus == UserPageStatus.PUBLIC, "publicPage": user.pageStatus == UserPageStatus.PUBLIC,
"openPage": user.pageStatus == UserPageStatus.OPEN, "openPage": user.pageStatus == UserPageStatus.OPEN,
"virtualDirectory": user.virtualDirectory, "virtualDirectory": user.virtualDirectory,
"accountImage": this.GetAccountImageURL(user.accountImage, handler) "accountImage": this.GetAccountImageURL(user.accountImage, h)
}; };
if(advanced) { if(advanced) {
@ -87,8 +87,12 @@ export class UserController {
info["allowPostFromFriendOnHisPage"] = user.allowPostsFromFriends; info["allowPostFromFriendOnHisPage"] = user.allowPostsFromFriends;
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["number_friends"] = user.friendsListPublic ? await FriendsHelper.CountForUser(user.id) : 0 info["number_friends"] = user.friendsListPublic ? await FriendsHelper.CountForUser(user.id) : 0
info["pageLikes"] = await LikesHelper.Count(user.id, LikesType.USER);
info["user_like_page"] = h.signedIn ? await LikesHelper.IsLiking(h.getUserId(), user.id, LikesType.USER) : false;
info["can_post_texts"] = await UserHelper.CanCreatePosts(h.getUserId(), user.id);
} }
return info; return info;

View File

@ -57,4 +57,27 @@ export class FriendsHelper {
} }
}) > 0; }) > 0;
} }
/**
* Check out whether friendship allows to create posts or not
*
* @param userID User wishing to create a post
* @param targetID Target user ID
*/
public static async CanPostTexts(userID: number, targetID: number) : Promise<boolean> {
const result = await DatabaseHelper.QueryRow({
table: FRIENDS_TABLE,
where: {
ID_personne: targetID,
ID_amis: userID,
actif: 1
},
fields: ["autoriser_post_page"]
});
if(result == null)
return false;
return result["autoriser_post_page"] == 1;
}
} }

View File

@ -125,6 +125,50 @@ export class UserHelper {
return (await this.GetUserInfo(userID)).pageStatus; return (await this.GetUserInfo(userID)).pageStatus;
} }
/**
* Check out whether a user allows posts from his
* friends on his page or not
*
* This is a convenience method
*
* @param userID Target user ID
*/
private static async AllowPostsOnHisPage(userID: number) : Promise<boolean> {
return (await this.GetUserInfo(userID)).allowPostsFromFriends;
}
/**
* Check out whether a user can create a post on another user
* page
*
* @param userID The user who wish to create a post
* @param targetID The target page
*/
public static async CanCreatePosts(userID: number, targetID: number) {
// User MUST be signed in
if(userID < 1)
return false;
// A user can always create posts on his page
if(userID == targetID) return true;
// User must be able to see the page
if(!await this.CanSeeUserPage(userID, targetID))
return false;
//Check if the user allow posts on his page
if(!await this.AllowPostsOnHisPage(targetID))
return false;
//Check if the friendship of the user allows him to create posts
if(!await FriendsHelper.CanPostTexts(userID, targetID))
return false;
// yes by default
return true;
}
private static async DbToUser(row: any) : Promise<User> { private static async DbToUser(row: any) : Promise<User> {
return new User({ return new User({