1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 05:19:22 +00:00

Can respond to a membership request

This commit is contained in:
Pierre HUBERT 2019-12-27 11:04:49 +01:00
parent e67d75d593
commit 6fab4bf8e3
3 changed files with 37 additions and 0 deletions

View File

@ -458,6 +458,27 @@ export class GroupsController {
h.success("User membership has been successfully updated!");
}
/**
* Respond to a membership request
*
* @param h Request handler
*/
public static async RespondRequest(h: RequestHandler) {
const groupID = await h.postGroupIDWithAccess("groupID", GroupsAccessLevel.MODERATOR_ACCESS);
const userID = await h.postUserId("userID");
const accept = h.postBool("accept");
if(await GroupsHelper.GetMembershipLevel(groupID, userID) != GroupMembershipLevels.PENDING)
h.error(401, "This user has not requested a membership for this group!");
// Respond to the request
await GroupsHelper.RespondRequest(groupID, userID, accept);
// TODO : create a notification
h.success("The response to the request has been successfully saved!");
}
/**
* Turn a GroupInfo object into a valid API object
*

View File

@ -118,4 +118,6 @@ export const Routes : Route[] = [
{path: "/groups/delete_member", cb: (h) => GroupsController.DeleteMember(h)},
{path: "/groups/update_membership_level", cb: (h) => GroupsController.UpdateMembership(h)},
{path: "/groups/respond_request", cb: (h) => GroupsController.RespondRequest(h)},
]

View File

@ -206,6 +206,20 @@ export class GroupsHelper {
await this.UpdateMembershipLevel(groupID, userID, GroupMembershipLevels.MEMBER);
}
/**
* Respond to a group membership request
*
* @param groupID Target groupID
* @param userID Target user ID
* @param accept TRUE to accept / FALSE else
*/
public static async RespondRequest(groupID: number, userID: number, accept: boolean) {
if(!accept)
await this.DeleteMember(groupID, userID);
else
await this.UpdateMembershipLevel(groupID, userID, GroupMembershipLevels.MEMBER);
}
/**
* Insert a new group member
*