mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 21:39:22 +00:00
Start to give advanced info about users
This commit is contained in:
parent
b756ff42bb
commit
8ebe93523e
@ -21,7 +21,7 @@ export class UserController {
|
|||||||
if(!user)
|
if(!user)
|
||||||
handler.error(404, "Could not get user data!");
|
handler.error(404, "Could not get user data!");
|
||||||
|
|
||||||
handler.send(this.UserToAPI(user, handler));
|
handler.send(await this.UserToAPI(user, handler));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,7 +41,7 @@ export class UserController {
|
|||||||
if(!user)
|
if(!user)
|
||||||
handler.error(404, "One user was not found!");
|
handler.error(404, "One user was not found!");
|
||||||
|
|
||||||
list[id] = this.UserToAPI(user, handler);
|
list[id] = await this.UserToAPI(user, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
handler.send(list);
|
handler.send(list);
|
||||||
@ -58,12 +58,15 @@ export class UserController {
|
|||||||
if(!await UserHelper.CanSeeUserPage(h.optionnalUserID, userID))
|
if(!await UserHelper.CanSeeUserPage(h.optionnalUserID, userID))
|
||||||
h.error(401, "You are not allowed to access these information!");
|
h.error(401, "You are not allowed to access these information!");
|
||||||
|
|
||||||
h.send("Go on");
|
const user = await UserHelper.GetUserInfo(userID);
|
||||||
|
const result = this.UserToAPI(user, h, true);
|
||||||
|
|
||||||
|
h.send(await result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static UserToAPI(user : User, handler: RequestHandler) : Object {
|
private static async UserToAPI(user : User, handler: RequestHandler, advanced: boolean = false) : Promise<Object> {
|
||||||
return {
|
const info = {
|
||||||
"userID": user.id,
|
"userID": user.id,
|
||||||
"firstName": user.firstName,
|
"firstName": user.firstName,
|
||||||
"lastName": user.lastName,
|
"lastName": user.lastName,
|
||||||
@ -72,6 +75,18 @@ export class UserController {
|
|||||||
"virtualDirectory": user.virtualDirectory,
|
"virtualDirectory": user.virtualDirectory,
|
||||||
"accountImage": this.GetAccountImageURL(user.accountImage, handler)
|
"accountImage": this.GetAccountImageURL(user.accountImage, handler)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if(advanced) {
|
||||||
|
info["friend_list_public"] = user.friendsListPublic;
|
||||||
|
info["personnalWebsite"] = user.hasWebsite ? user.personnalWebsite : "";
|
||||||
|
info["publicNote"] = user.hasPublicNote ? user.publicNote : "";
|
||||||
|
info["noCommentOnHisPage"] = user.blockComments;
|
||||||
|
info["allowPostFromFriendOnHisPage"] = user.allowPostsFromFriends;
|
||||||
|
info["account_creation_time"] = user.timeCreate;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GetAccountImageURL(image : AccountImage, handler: RequestHandler) {
|
private static GetAccountImageURL(image : AccountImage, handler: RequestHandler) {
|
||||||
|
@ -20,9 +20,19 @@ export interface UserBuilder {
|
|||||||
virtualDirectory: string,
|
virtualDirectory: string,
|
||||||
pageStatus: UserPageStatus,
|
pageStatus: UserPageStatus,
|
||||||
accountImage: AccountImage,
|
accountImage: AccountImage,
|
||||||
|
friendsListPublic: boolean,
|
||||||
|
personnalWebsite ?: string,
|
||||||
|
publicNote ?: string,
|
||||||
|
blockComments : boolean,
|
||||||
|
allowPostsFromFriends: boolean,
|
||||||
}
|
}
|
||||||
|
|
||||||
export class User {
|
export class User implements UserBuilder {
|
||||||
|
friendsListPublic: boolean;
|
||||||
|
personnalWebsite?: string;
|
||||||
|
publicNote?: string;
|
||||||
|
blockComments: boolean;
|
||||||
|
allowPostsFromFriends: boolean;
|
||||||
id: number;
|
id: number;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
lastName: string;
|
lastName: string;
|
||||||
@ -32,13 +42,24 @@ export class User {
|
|||||||
accountImage: AccountImage;
|
accountImage: AccountImage;
|
||||||
|
|
||||||
public constructor(info : UserBuilder) {
|
public constructor(info : UserBuilder) {
|
||||||
this.id = info.id;
|
for (const key in info) {
|
||||||
this.firstName = info.firstName;
|
if (info.hasOwnProperty(key)) {
|
||||||
this.lastName = info.lastName;
|
this[key] = info[key];
|
||||||
this.timeCreate = info.timeCreate;
|
}
|
||||||
this.virtualDirectory = info.virtualDirectory;
|
}
|
||||||
this.pageStatus = info.pageStatus;
|
|
||||||
this.accountImage = info.accountImage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get hasWebsite() : boolean {
|
||||||
|
return this.personnalWebsite
|
||||||
|
&& this.personnalWebsite != null
|
||||||
|
&& this.personnalWebsite.length > 0
|
||||||
|
&& this.personnalWebsite != "null"
|
||||||
|
}
|
||||||
|
|
||||||
|
get hasPublicNote() : boolean {
|
||||||
|
return this.publicNote
|
||||||
|
&& this.publicNote != null
|
||||||
|
&& this.publicNote.length > 0
|
||||||
|
&& this.publicNote != "null"
|
||||||
|
}
|
||||||
}
|
}
|
@ -134,7 +134,12 @@ export class UserHelper {
|
|||||||
timeCreate: new Date(row.date_creation).getTime()/1000,
|
timeCreate: new Date(row.date_creation).getTime()/1000,
|
||||||
virtualDirectory: row.sous_repertoire,
|
virtualDirectory: row.sous_repertoire,
|
||||||
pageStatus: row.pageouverte == 1 ? UserPageStatus.OPEN : (row.public == 1 ? UserPageStatus.PUBLIC : UserPageStatus.PRIVATE),
|
pageStatus: row.pageouverte == 1 ? UserPageStatus.OPEN : (row.public == 1 ? UserPageStatus.PUBLIC : UserPageStatus.PRIVATE),
|
||||||
accountImage: await AccountImageHelper.Get(row.ID)
|
accountImage: await AccountImageHelper.Get(row.ID),
|
||||||
|
friendsListPublic: row.liste_amis_publique == 1,
|
||||||
|
personnalWebsite: row.site_web,
|
||||||
|
publicNote: row.public_note,
|
||||||
|
blockComments: row.bloquecommentaire == 1,
|
||||||
|
allowPostsFromFriends: row.autoriser_post_amis == 1,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user