1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-12-28 14:38:52 +00:00

Return more information about groups

This commit is contained in:
Pierre HUBERT 2019-12-24 19:15:12 +01:00
parent 0925b44492
commit f06f772420
2 changed files with 24 additions and 3 deletions

View File

@ -125,20 +125,23 @@ export class GroupsController {
const group = await GroupsHelper.GetInfo(groupID);
h.send(await this.GroupInfoToAPI(group, h));
h.send(await this.GroupInfoToAPI(group, h, true));
}
/**
* Turn a GroupInfo object into a valid API object
*
* @param info Information about the group
* @param h Request handler
* @param advanced Specify whether advanced information should be returned
* in the request or not
* @returns Generated object
*/
private static async GroupInfoToAPI(info: GroupInfo, h: RequestHandler) : Promise<any> {
private static async GroupInfoToAPI(info: GroupInfo, h: RequestHandler, advanced: boolean = false) : Promise<any> {
const membership = await GroupsHelper.GetMembershipInfo(info.id, h.getUserId())
return {
const data = {
id: info.id,
name: info.name,
icon_url: info.logoURL,
@ -151,5 +154,15 @@ export class GroupsController {
membership: GROUPS_MEMBERSHIP_LEVELS[membership ? membership.level : GroupMembershipLevels.VISITOR],
following: membership ? membership.following : false
}
if(advanced) {
data["time_create"] = info.timeCreate;
data["description"] = info.hasDescription ? info.description : "null";
data["url"] = info.url ? info.hasURL : "null";
//TODO : add likes information
}
return data;
}
}

View File

@ -95,4 +95,12 @@ export class GroupInfo implements GroupInfoConstructor {
get logoURL() : string {
return pathUserData(this.logoPath, false);
}
get hasDescription() : boolean {
return this.description && true;
}
get hasURL() : boolean {
return this.url && true;
}
}