mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-04 11:34:04 +00:00 
			
		
		
		
	Start to give advanced info about users
This commit is contained in:
		@@ -21,7 +21,7 @@ export class UserController {
 | 
			
		||||
		if(!user)
 | 
			
		||||
			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)
 | 
			
		||||
				handler.error(404, "One user was not found!");
 | 
			
		||||
			
 | 
			
		||||
			list[id] = this.UserToAPI(user, handler);
 | 
			
		||||
			list[id] = await this.UserToAPI(user, handler);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		handler.send(list);
 | 
			
		||||
@@ -58,12 +58,15 @@ export class UserController {
 | 
			
		||||
		if(!await UserHelper.CanSeeUserPage(h.optionnalUserID, userID))
 | 
			
		||||
			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 {
 | 
			
		||||
		return {
 | 
			
		||||
	private static async UserToAPI(user : User, handler: RequestHandler, advanced: boolean = false) : Promise<Object> {
 | 
			
		||||
		const info = {
 | 
			
		||||
			"userID": user.id,
 | 
			
		||||
			"firstName": user.firstName,
 | 
			
		||||
			"lastName": user.lastName,
 | 
			
		||||
@@ -72,6 +75,18 @@ export class UserController {
 | 
			
		||||
			"virtualDirectory": user.virtualDirectory,
 | 
			
		||||
			"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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -20,9 +20,19 @@ export interface UserBuilder {
 | 
			
		||||
	virtualDirectory: string,
 | 
			
		||||
	pageStatus: UserPageStatus,
 | 
			
		||||
	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;
 | 
			
		||||
	firstName: string;
 | 
			
		||||
	lastName: string;
 | 
			
		||||
@@ -32,13 +42,24 @@ export class User {
 | 
			
		||||
	accountImage: AccountImage;
 | 
			
		||||
 | 
			
		||||
	public constructor(info : UserBuilder) {
 | 
			
		||||
		this.id = info.id;
 | 
			
		||||
		this.firstName = info.firstName;
 | 
			
		||||
		this.lastName = info.lastName;
 | 
			
		||||
		this.timeCreate = info.timeCreate;
 | 
			
		||||
		this.virtualDirectory = info.virtualDirectory;
 | 
			
		||||
		this.pageStatus = info.pageStatus;
 | 
			
		||||
		this.accountImage = info.accountImage;
 | 
			
		||||
		for (const key in info) {
 | 
			
		||||
			if (info.hasOwnProperty(key)) {
 | 
			
		||||
				this[key] = info[key];
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	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,
 | 
			
		||||
			virtualDirectory: row.sous_repertoire,
 | 
			
		||||
			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,
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user