From b396dcd01cceda23cf972f2dded910aa9da78560 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 27 Dec 2019 18:24:18 +0100 Subject: [PATCH] Can cancel a group membership invitation --- src/controllers/GroupsController.ts | 20 ++++++++++++++++++++ src/controllers/Routes.ts | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/controllers/GroupsController.ts b/src/controllers/GroupsController.ts index c9de1bf..5a621f2 100644 --- a/src/controllers/GroupsController.ts +++ b/src/controllers/GroupsController.ts @@ -496,6 +496,26 @@ export class GroupsController { h.send(this.GroupMemberToAPI(membership)); } + /** + * Cancel a group membership invitation + * + * @param h Request handler + */ + public static async CancelInvitation(h: RequestHandler) { + const groupID = await h.postGroupIDWithAccess("groupID", GroupsAccessLevel.MODERATOR_ACCESS); + const userID = await h.postUserId("userID"); + + if(await GroupsHelper.GetMembershipLevel(groupID, userID) != GroupMembershipLevels.INVITED) + h.error(401, "This user has not been invited to join this group!"); + + // Cancel group invitation + await GroupsHelper.DeleteMember(groupID, userID); + + // TODO : delete related notifications + + h.success("Membership invitation has been cancelled!"); + } + /** * Turn a GroupInfo object into a valid API object * diff --git a/src/controllers/Routes.ts b/src/controllers/Routes.ts index ae504de..965662c 100644 --- a/src/controllers/Routes.ts +++ b/src/controllers/Routes.ts @@ -122,4 +122,6 @@ export const Routes : Route[] = [ {path: "/groups/respond_request", cb: (h) => GroupsController.RespondRequest(h)}, {path: "/groups/get_membership", cb: (h) => GroupsController.GetMembership(h)}, + + {path: "/groups/cancel_invitation", cb: (h) => GroupsController.CancelInvitation(h)}, ] \ No newline at end of file