mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 13:29:22 +00:00
Can get the list of members of a group
This commit is contained in:
parent
84a98506dc
commit
a258f949c1
@ -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)},
|
||||
]
|
@ -292,6 +292,21 @@ export class GroupsHelper {
|
||||
return currID < 1 || currID == groupID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entire list of members of a group
|
||||
*
|
||||
* @param groupID Target Group ID
|
||||
*/
|
||||
public static async GetListMembers(groupID: number) : Promise<Array<GroupMember>> {
|
||||
const members = await DatabaseHelper.Query({
|
||||
table: GROUPS_MEMBERS_TABLE,
|
||||
where: {
|
||||
groups_id: groupID
|
||||
}
|
||||
});
|
||||
|
||||
return members.map((row) => this.DbToGroupMember(row));
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of members of a group
|
||||
@ -337,12 +352,12 @@ export class GroupsHelper {
|
||||
* @param row Database entry
|
||||
* @returns Generated object
|
||||
*/
|
||||
private static async DbToGroupMember(row: any) : Promise<GroupMember> {
|
||||
private static DbToGroupMember(row: any) : GroupMember {
|
||||
return new GroupMember({
|
||||
id: row.id,
|
||||
groupID: row.groups_id,
|
||||
userID: row.user_id,
|
||||
timeCreate: row.time_create,
|
||||
userID: Number(row.user_id),
|
||||
timeCreate: Number(row.time_create),
|
||||
level: row.level,
|
||||
following: row.following == 1
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user