Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix(backend): allow userEmail filter in allShortcodes query (#6679)

Mir Arif Hasan0d75567c961b
diff --git a/packages/hoppscotch-backend/src/admin/infra.resolver.ts b/packages/hoppscotch-backend/src/admin/infra.resolver.ts
index 61e6869eb..431a3ee1a 100644
--- a/packages/hoppscotch-backend/src/admin/infra.resolver.ts
+++ b/packages/hoppscotch-backend/src/admin/infra.resolver.ts
@@ -34,7 +34,11 @@ import {
} from 'src/infra-config/input-args';
import { InfraConfigEnum } from 'src/types/InfraConfig';
import { ServiceStatus } from 'src/infra-config/helper';
-import { FetchAllTeamsV2Args, FetchAllUsersV2Args } from './input-types.args';
+import {
+ FetchAllShortcodesArgs,
+ FetchAllTeamsV2Args,
+ FetchAllUsersV2Args,
+} from './input-types.args';
@UseGuards(GqlThrottlerGuard)
@Resolver(() => Infra)
@@ -255,19 +259,11 @@ export class InfraResolver {
@ResolveField(() => [ShortcodeWithUserEmail], {
description: 'Returns a list of all the shortcodes in the infra',
})
- async allShortcodes(
- @Args() args: PaginationArgs,
- @Args({
- name: 'userEmail',
- nullable: true,
- description: 'Users email to filter shortcodes by',
- })
- userEmail: string,
- ) {
+ async allShortcodes(@Args() args: FetchAllShortcodesArgs) {
return await this.adminService.fetchAllShortcodes(
args.cursor,
args.take,
- userEmail,
+ args.userEmail,
);
}
diff --git a/packages/hoppscotch-backend/src/admin/input-types.args.ts b/packages/hoppscotch-backend/src/admin/input-types.args.ts
index d7f125839..4cdeaeca4 100644
--- a/packages/hoppscotch-backend/src/admin/input-types.args.ts
+++ b/packages/hoppscotch-backend/src/admin/input-types.args.ts
@@ -1,7 +1,22 @@
import { Field, ID, ArgsType } from '@nestjs/graphql';
import { TeamAccessRole } from '../team/team.model';
import { IsEnum, IsNotEmpty, IsOptional, IsString } from 'class-validator';
-import { OffsetPaginationArgs } from 'src/types/input-types.args';
+import {
+ OffsetPaginationArgs,
+ PaginationArgs,
+} from 'src/types/input-types.args';
+
+@ArgsType()
+export class FetchAllShortcodesArgs extends PaginationArgs {
+ @Field({
+ name: 'userEmail',
+ nullable: true,
+ description: "User's email to filter shortcodes by",
+ })
+ @IsString()
+ @IsOptional()
+ userEmail: string;
+}
@ArgsType()
export class FetchAllUsersV2Args extends OffsetPaginationArgs {