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: class validation issue for updateRESTUserRequest (#6373)

Mir Arif Hasanfeaf990af650
diff --git a/packages/hoppscotch-backend/src/user-request/input-type.args.ts b/packages/hoppscotch-backend/src/user-request/input-type.args.ts
index 1c2f17b99..8386269ff 100644
--- a/packages/hoppscotch-backend/src/user-request/input-type.args.ts
+++ b/packages/hoppscotch-backend/src/user-request/input-type.args.ts
@@ -73,6 +73,13 @@ export class CreateUserRequestArgs {
@ArgsType()
export class UpdateUserRequestArgs {
+ @Field(() => ID, {
+ description: 'ID of the user request',
+ })
+ @IsString()
+ @IsNotEmpty()
+ id: string;
+
@Field({
nullable: true,
defaultValue: undefined,
diff --git a/packages/hoppscotch-backend/src/user-request/resolvers/user-request.resolver.ts b/packages/hoppscotch-backend/src/user-request/resolvers/user-request.resolver.ts
index aaff691af..bad953ed5 100644
--- a/packages/hoppscotch-backend/src/user-request/resolvers/user-request.resolver.ts
+++ b/packages/hoppscotch-backend/src/user-request/resolvers/user-request.resolver.ts
@@ -146,16 +146,10 @@ export class UserRequestResolver {
@UseGuards(GqlAuthGuard)
async updateRESTUserRequest(
@GqlUser() user: AuthUser,
- @Args({
- name: 'id',
- description: 'ID of the user REST request',
- type: () => ID,
- })
- id: string,
@Args() args: UpdateUserRequestArgs,
) {
const request = await this.userRequestService.updateRequest(
- id,
+ args.id,
args.title,
ReqType.REST,
args.request,
@@ -171,16 +165,10 @@ export class UserRequestResolver {
@UseGuards(GqlAuthGuard)
async updateGQLUserRequest(
@GqlUser() user: AuthUser,
- @Args({
- name: 'id',
- description: 'ID of the user GraphQL request',
- type: () => ID,
- })
- id: string,
@Args() args: UpdateUserRequestArgs,
) {
const request = await this.userRequestService.updateRequest(
- id,
+ args.id,
args.title,
ReqType.GQL,
args.request,
diff --git a/packages/hoppscotch-backend/src/user-request/user-request.service.spec.ts b/packages/hoppscotch-backend/src/user-request/user-request.service.spec.ts
index a4e6f9d7a..bc645c094 100644
--- a/packages/hoppscotch-backend/src/user-request/user-request.service.spec.ts
+++ b/packages/hoppscotch-backend/src/user-request/user-request.service.spec.ts
@@ -379,6 +379,7 @@ describe('UserRequestService', () => {
const id = userRequests[0].id;
const type = userRequests[0].type;
const args: UpdateUserRequestArgs = {
+ id,
title: userRequests[0].title,
request: userRequests[0].request,
};
@@ -401,6 +402,7 @@ describe('UserRequestService', () => {
const id = userRequests[0].id;
const type = userRequests[0].type;
const args: UpdateUserRequestArgs = {
+ id,
title: userRequests[0].title,
request: userRequests[0].request,
};
@@ -420,7 +422,7 @@ describe('UserRequestService', () => {
expect(mockPrisma.userRequest.update).toHaveBeenCalledWith({
where: { id },
data: {
- ...args,
+ title: args.title,
request: JSON.parse(args.request),
},
});
@@ -429,6 +431,7 @@ describe('UserRequestService', () => {
const id = userRequests[0].id;
const type = userRequests[0].type;
const args: UpdateUserRequestArgs = {
+ id,
title: userRequests[0].title,
request: userRequests[0].request,
};
@@ -454,6 +457,7 @@ describe('UserRequestService', () => {
const id = userRequests[0].id;
const type = userRequests[0].type;
const args: UpdateUserRequestArgs = {
+ id,
title: userRequests[0].title,
request: userRequests[0].request,
};
@@ -474,6 +478,7 @@ describe('UserRequestService', () => {
const id = userRequests[0].id;
const type = userRequests[0].type;
const args: UpdateUserRequestArgs = {
+ id,
title: userRequests[0].title,
request: 'invalid json',
};