From 88f6a4ae26a2117f578d7512cac7185c85659105 Mon Sep 17 00:00:00 2001 From: Ankit Sridhar <36269838+ankitsridhar16@users.noreply.github.com> Date: Thu, 3 Aug 2023 14:08:32 +0530 Subject: [PATCH] [feat] : Allow admins to revoke a team invite (HBE-230) (#3162) feat: added functionality for admin to revoke team invite --- .../src/admin/admin.resolver.ts | 17 +++++++++++++++++ .../src/admin/admin.service.ts | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/packages/hoppscotch-backend/src/admin/admin.resolver.ts b/packages/hoppscotch-backend/src/admin/admin.resolver.ts index 12838963a..d8832071f 100644 --- a/packages/hoppscotch-backend/src/admin/admin.resolver.ts +++ b/packages/hoppscotch-backend/src/admin/admin.resolver.ts @@ -411,6 +411,23 @@ export class AdminResolver { return deletedTeam.right; } + @Mutation(() => Boolean, { + description: 'Revoke a team Invite by Invite ID', + }) + @UseGuards(GqlAuthGuard, GqlAdminGuard) + async revokeTeamInviteByAdmin( + @Args({ + name: 'inviteID', + description: 'Team Invite ID', + type: () => ID, + }) + inviteID: string, + ): Promise { + const invite = await this.adminService.revokeTeamInviteByID(inviteID); + if (E.isLeft(invite)) throwErr(invite.left); + return true; + } + /* Subscriptions */ @Subscription(() => InvitedUser, { diff --git a/packages/hoppscotch-backend/src/admin/admin.service.ts b/packages/hoppscotch-backend/src/admin/admin.service.ts index ab1f1dc9c..1ac4102ae 100644 --- a/packages/hoppscotch-backend/src/admin/admin.service.ts +++ b/packages/hoppscotch-backend/src/admin/admin.service.ts @@ -11,6 +11,7 @@ import { INVALID_EMAIL, ONLY_ONE_ADMIN_ACCOUNT, TEAM_INVITE_ALREADY_MEMBER, + TEAM_INVITE_NO_INVITE_FOUND, USER_ALREADY_INVITED, USER_IS_ADMIN, USER_NOT_FOUND, @@ -416,4 +417,19 @@ export class AdminService { if (E.isLeft(team)) return E.left(team.left); return E.right(team.right); } + + /** + * Revoke a team invite by ID + * @param inviteID Team Invite ID + * @returns an Either of boolean or error + */ + async revokeTeamInviteByID(inviteID: string) { + const teamInvite = await this.teamInvitationService.revokeInvitation( + inviteID, + ); + + if (E.isLeft(teamInvite)) return E.left(teamInvite.left); + + return E.right(teamInvite.right); + } }