mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-21 00:55:17 +00:00
Can get the list of members of a group
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import { RequestHandler } from "../entities/RequestHandler";
|
||||
import { GroupsHelper, PATH_GROUPS_LOGOS } from "../helpers/GroupsHelper";
|
||||
import { GroupsAccessLevel, GroupInfo, GroupVisibilityLevel, GroupPostsCreationLevel, GroupRegistrationLevel } from "../entities/Group";
|
||||
import { GroupMembershipLevels } from "../entities/GroupMember";
|
||||
import { GroupMembershipLevels, GroupMember } from "../entities/GroupMember";
|
||||
import { time } from "../utils/DateUtils";
|
||||
import { LikesHelper, LikesType } from "../helpers/LikesHelper";
|
||||
import { GroupSettings } from "../entities/GroupSettings";
|
||||
@ -275,6 +275,20 @@ export class GroupsController {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entire list of members of the group
|
||||
*
|
||||
* @param h Request handler
|
||||
*/
|
||||
public static async GetMembers(h: RequestHandler) {
|
||||
const groupID = await h.postGroupIDWithAccess("id", GroupsAccessLevel.MODERATOR_ACCESS);
|
||||
|
||||
const members = await GroupsHelper.GetListMembers(groupID);
|
||||
|
||||
// Parse the list of members
|
||||
h.send(members.map((m) => this.GroupMemberToAPI(m)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a GroupInfo object into a valid API object
|
||||
*
|
||||
@ -313,4 +327,18 @@ export class GroupsController {
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a {GroupMember} object into an API entry
|
||||
*
|
||||
* @param m Group Member to transform
|
||||
*/
|
||||
private static GroupMemberToAPI(m: GroupMember) : Object {
|
||||
return {
|
||||
user_id: m.userID,
|
||||
group_id: m.groupID,
|
||||
time_create: m.timeCreate,
|
||||
level: GROUPS_MEMBERSHIP_LEVELS[m.level]
|
||||
};
|
||||
}
|
||||
}
|
@ -104,4 +104,6 @@ export const Routes : Route[] = [
|
||||
{path: "/groups/upload_logo", cb: (h) => GroupsController.UploadLogo(h)},
|
||||
|
||||
{path: "/groups/delete_logo", cb: (h) => GroupsController.DeleteLogo(h)},
|
||||
|
||||
{path: "/groups/get_members", cb: (h) => GroupsController.GetMembers(h)},
|
||||
]
|
Reference in New Issue
Block a user