From 9d6a7f709c224c822bf1d69729840ad9d3734e43 Mon Sep 17 00:00:00 2001 From: Ankit Sridhar <36269838+ankitsridhar16@users.noreply.github.com> Date: Tue, 28 Mar 2023 15:35:38 +0530 Subject: [PATCH] feat: introducing get team info by id in admin module as a query (HBE-182) (#54) * feat: introducing get team info by id in admin module as a query * chore: adding resolve field for admin * chore: remove nullable false * refactor: rename getTeamInfo to teamInfo * refactor: make myRole nullable --- .../src/admin/admin.resolver.ts | 16 ++++++++++++++++ .../src/admin/admin.service.ts | 11 +++++++++++ .../hoppscotch-backend/src/team/team.resolver.ts | 1 + 3 files changed, 28 insertions(+) diff --git a/packages/hoppscotch-backend/src/admin/admin.resolver.ts b/packages/hoppscotch-backend/src/admin/admin.resolver.ts index 2cdc24d1b..6b68e616d 100644 --- a/packages/hoppscotch-backend/src/admin/admin.resolver.ts +++ b/packages/hoppscotch-backend/src/admin/admin.resolver.ts @@ -102,6 +102,22 @@ export class AdminResolver { const teams = await this.adminService.fetchAllTeams(args.cursor, args.take); return teams; } + @ResolveField(() => Team, { + description: 'Returns a team info by ID when requested by Admin', + }) + async teamInfo( + @Parent() admin: Admin, + @Args({ + name: 'teamID', + type: () => ID, + description: 'Team ID for which info to fetch', + }) + teamID: string, + ): Promise { + const team = await this.adminService.getTeamInfo(teamID); + if (E.isLeft(team)) throwErr(team.left); + return team.right; + } @ResolveField(() => Number, { description: 'Return count of all the members in a team', diff --git a/packages/hoppscotch-backend/src/admin/admin.service.ts b/packages/hoppscotch-backend/src/admin/admin.service.ts index 2afc53123..290a5eaca 100644 --- a/packages/hoppscotch-backend/src/admin/admin.service.ts +++ b/packages/hoppscotch-backend/src/admin/admin.service.ts @@ -393,4 +393,15 @@ export class AdminService { const teamRequestCount = this.teamRequestService.getTeamRequestsCount(); return teamRequestCount; } + + /** + * Get team info by ID + * @param teamID Team ID + * @returns an Either of `Team` or error + */ + async getTeamInfo(teamID: string) { + const team = await this.teamService.getTeamWithIDTE(teamID)(); + if (E.isLeft(team)) return E.left(team.left); + return E.right(team.right); + } } diff --git a/packages/hoppscotch-backend/src/team/team.resolver.ts b/packages/hoppscotch-backend/src/team/team.resolver.ts index 94c3ce29b..aeb4bc228 100644 --- a/packages/hoppscotch-backend/src/team/team.resolver.ts +++ b/packages/hoppscotch-backend/src/team/team.resolver.ts @@ -61,6 +61,7 @@ export class TeamResolver { @ResolveField(() => TeamMemberRole, { description: 'The role of the current user in the team', + nullable: true, }) @UseGuards(GqlAuthGuard) myRole(