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:
parent
e67d75d593
commit
6fab4bf8e3
@ -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
|
||||
*
|
||||
|
@ -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)},
|
||||
]
|
@ -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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user