From 675bf79c6eaf84b054dfc272482fd1969e095959 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 27 Dec 2019 11:11:05 +0100 Subject: [PATCH] Can get information about a single user membership --- src/controllers/GroupsController.ts | 17 +++++++++++++++++ src/controllers/Routes.ts | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/controllers/GroupsController.ts b/src/controllers/GroupsController.ts index d083ea3..c9de1bf 100644 --- a/src/controllers/GroupsController.ts +++ b/src/controllers/GroupsController.ts @@ -479,6 +479,23 @@ export class GroupsController { h.success("The response to the request has been successfully saved!"); } + /** + * Get information about a single membership + * + * @param h Request handler + */ + public static async GetMembership(h: RequestHandler) { + const groupID = await h.postGroupIDWithAccess("groupID", GroupsAccessLevel.MODERATOR_ACCESS); + const userID = await h.postUserId("userID"); + + const membership = await GroupsHelper.GetMembershipInfo(groupID, userID); + + if(membership == null) + h.error(404, "Specified user does not have any membership in this group!"); + + h.send(this.GroupMemberToAPI(membership)); + } + /** * Turn a GroupInfo object into a valid API object * diff --git a/src/controllers/Routes.ts b/src/controllers/Routes.ts index 9209dff..ae504de 100644 --- a/src/controllers/Routes.ts +++ b/src/controllers/Routes.ts @@ -120,4 +120,6 @@ export const Routes : Route[] = [ {path: "/groups/update_membership_level", cb: (h) => GroupsController.UpdateMembership(h)}, {path: "/groups/respond_request", cb: (h) => GroupsController.RespondRequest(h)}, + + {path: "/groups/get_membership", cb: (h) => GroupsController.GetMembership(h)}, ] \ No newline at end of file