From fad4a6444557089be3c71b766c4440f7e2d21960 Mon Sep 17 00:00:00 2001 From: Mir Arif Hasan Date: Fri, 13 Oct 2023 14:44:23 +0600 Subject: [PATCH] feat: deprecated tag added in some admin ResolveFields --- .../src/admin/admin.model.ts | 3 +- .../src/admin/admin.resolver.ts | 225 +++++++++++++++++- 2 files changed, 219 insertions(+), 9 deletions(-) diff --git a/packages/hoppscotch-backend/src/admin/admin.model.ts b/packages/hoppscotch-backend/src/admin/admin.model.ts index bf4288dd4..0ee09d852 100644 --- a/packages/hoppscotch-backend/src/admin/admin.model.ts +++ b/packages/hoppscotch-backend/src/admin/admin.model.ts @@ -1,4 +1,5 @@ import { ObjectType } from '@nestjs/graphql'; +import { User } from 'src/user/user.model'; @ObjectType() -export class Admin {} +export class Admin extends User {} diff --git a/packages/hoppscotch-backend/src/admin/admin.resolver.ts b/packages/hoppscotch-backend/src/admin/admin.resolver.ts index 35a93cde0..ebf1c08df 100644 --- a/packages/hoppscotch-backend/src/admin/admin.resolver.ts +++ b/packages/hoppscotch-backend/src/admin/admin.resolver.ts @@ -1,4 +1,13 @@ -import { Args, ID, Mutation, Resolver, Subscription } from '@nestjs/graphql'; +import { + Args, + ID, + Mutation, + Parent, + Query, + ResolveField, + Resolver, + Subscription, +} from '@nestjs/graphql'; import { Admin } from './admin.model'; import { UseGuards } from '@nestjs/common'; import { GqlAuthGuard } from '../guards/gql-auth.guard'; @@ -18,6 +27,9 @@ import { } from './input-types.args'; import { GqlThrottlerGuard } from 'src/guards/gql-throttler.guard'; import { SkipThrottle } from '@nestjs/throttler'; +import { User } from 'src/user/user.model'; +import { PaginationArgs } from 'src/types/input-types.args'; +import { TeamInvitation } from 'src/team-invitation/team-invitation.model'; @UseGuards(GqlThrottlerGuard) @Resolver(() => Admin) @@ -29,13 +41,210 @@ export class AdminResolver { /* Query */ - // @Query(() => Admin, { - // description: 'Gives details of the admin executing this query', - // }) - // @UseGuards(GqlAuthGuard, GqlAdminGuard) - // admin(@GqlAdmin() admin: Admin) { - // return admin; - // } + @Query(() => Admin, { + description: 'Gives details of the admin executing this query', + }) + @UseGuards(GqlAuthGuard, GqlAdminGuard) + admin(@GqlAdmin() admin: Admin) { + return admin; + } + + @ResolveField(() => [User], { + description: 'Returns a list of all admin users in infra', + deprecationReason: 'Use `infra` query instead', + }) + @UseGuards(GqlAuthGuard, GqlAdminGuard) + async admins() { + const admins = await this.adminService.fetchAdmins(); + return admins; + } + @ResolveField(() => User, { + description: 'Returns a user info by UID', + deprecationReason: 'Use `infra` query instead', + }) + @UseGuards(GqlAuthGuard, GqlAdminGuard) + async userInfo( + @Args({ + name: 'userUid', + type: () => ID, + description: 'The user UID', + }) + userUid: string, + ): Promise { + const user = await this.adminService.fetchUserInfo(userUid); + if (E.isLeft(user)) throwErr(user.left); + return user.right; + } + + @ResolveField(() => [User], { + description: 'Returns a list of all the users in infra', + deprecationReason: 'Use `infra` query instead', + }) + @UseGuards(GqlAuthGuard, GqlAdminGuard) + async allUsers( + @Parent() admin: Admin, + @Args() args: PaginationArgs, + ): Promise { + const users = await this.adminService.fetchUsers(args.cursor, args.take); + return users; + } + + @ResolveField(() => [InvitedUser], { + description: 'Returns a list of all the invited users', + deprecationReason: 'Use `infra` query instead', + }) + async invitedUsers(@Parent() admin: Admin): Promise { + const users = await this.adminService.fetchInvitedUsers(); + return users; + } + + @ResolveField(() => [Team], { + description: 'Returns a list of all the teams in the infra', + deprecationReason: 'Use `infra` query instead', + }) + async allTeams( + @Parent() admin: Admin, + @Args() args: PaginationArgs, + ): Promise { + 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', + deprecationReason: 'Use `infra` query instead', + }) + 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', + deprecationReason: 'Use `infra` query instead', + }) + async membersCountInTeam( + @Parent() admin: Admin, + @Args({ + name: 'teamID', + type: () => ID, + description: 'Team ID for which team members to fetch', + nullable: false, + }) + teamID: string, + ): Promise { + const teamMembersCount = await this.adminService.membersCountInTeam(teamID); + return teamMembersCount; + } + + @ResolveField(() => Number, { + description: 'Return count of all the stored collections in a team', + deprecationReason: 'Use `infra` query instead', + }) + async collectionCountInTeam( + @Parent() admin: Admin, + @Args({ + name: 'teamID', + type: () => ID, + description: 'Team ID for which team members to fetch', + }) + teamID: string, + ): Promise { + const teamCollCount = await this.adminService.collectionCountInTeam(teamID); + return teamCollCount; + } + @ResolveField(() => Number, { + description: 'Return count of all the stored requests in a team', + deprecationReason: 'Use `infra` query instead', + }) + async requestCountInTeam( + @Parent() admin: Admin, + @Args({ + name: 'teamID', + type: () => ID, + description: 'Team ID for which team members to fetch', + }) + teamID: string, + ): Promise { + const teamReqCount = await this.adminService.requestCountInTeam(teamID); + return teamReqCount; + } + + @ResolveField(() => Number, { + description: 'Return count of all the stored environments in a team', + deprecationReason: 'Use `infra` query instead', + }) + async environmentCountInTeam( + @Parent() admin: Admin, + @Args({ + name: 'teamID', + type: () => ID, + description: 'Team ID for which team members to fetch', + }) + teamID: string, + ): Promise { + const envsCount = await this.adminService.environmentCountInTeam(teamID); + return envsCount; + } + + @ResolveField(() => [TeamInvitation], { + description: 'Return all the pending invitations in a team', + deprecationReason: 'Use `infra` query instead', + }) + async pendingInvitationCountInTeam( + @Parent() admin: Admin, + @Args({ + name: 'teamID', + type: () => ID, + description: 'Team ID for which team members to fetch', + }) + teamID: string, + ) { + const invitations = await this.adminService.pendingInvitationCountInTeam( + teamID, + ); + return invitations; + } + + @ResolveField(() => Number, { + description: 'Return total number of Users in organization', + deprecationReason: 'Use `infra` query instead', + }) + async usersCount() { + return this.adminService.getUsersCount(); + } + + @ResolveField(() => Number, { + description: 'Return total number of Teams in organization', + deprecationReason: 'Use `infra` query instead', + }) + async teamsCount() { + return this.adminService.getTeamsCount(); + } + + @ResolveField(() => Number, { + description: 'Return total number of Team Collections in organization', + deprecationReason: 'Use `infra` query instead', + }) + async teamCollectionsCount() { + return this.adminService.getTeamCollectionsCount(); + } + + @ResolveField(() => Number, { + description: 'Return total number of Team Requests in organization', + deprecationReason: 'Use `infra` query instead', + }) + async teamRequestsCount() { + return this.adminService.getTeamRequestsCount(); + } /* Mutations */