diff --git a/src/controllers/GroupsController.ts b/src/controllers/GroupsController.ts index a30f441..ddb70a0 100644 --- a/src/controllers/GroupsController.ts +++ b/src/controllers/GroupsController.ts @@ -368,6 +368,25 @@ export class GroupsController { h.success("The membership has been successfully saved!"); } + /** + * Cancel a membership request + * + * @param h Request handler + */ + public static async CancelRequest(h: RequestHandler) { + const groupID = await h.postGroupIDWithAccess("id", GroupsAccessLevel.LIMITED_ACCESS); + + if(await GroupsHelper.GetMembershipLevel(groupID, h.getUserId()) != GroupMembershipLevels.PENDING) + h.error(401, "You did not send a membership request to this group!"); + + // Delete membership of the user + await GroupsHelper.DeleteMember(groupID, h.getUserId()); + + // TODO : delete any potential notificaton + + h.success("The request has been successfully cancelled!"); + } + /** * Turn a GroupInfo object into a valid API object * diff --git a/src/controllers/Routes.ts b/src/controllers/Routes.ts index a100761..ac2e489 100644 --- a/src/controllers/Routes.ts +++ b/src/controllers/Routes.ts @@ -112,4 +112,6 @@ export const Routes : Route[] = [ {path: "/groups/respond_invitation", cb: (h) => GroupsController.RespondInvitation(h)}, {path: "/groups/send_request", cb: (h) => GroupsController.SendRequest(h)}, + + {path: "/groups/cancel_request", cb: (h) => GroupsController.CancelRequest(h)}, ] \ No newline at end of file