Skip to content

Commit f916f1b

Browse files
fix: add automatic string-to-number transformation for pagination parameters
Added @type(() => Number) decorators to skip, first, and last pagination parameters to automatically convert query string parameters to integers before validation, fixing 'must be an integer' validation errors.
1 parent 13e32f8 commit f916f1b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/common/pagination/pagination.args.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { ArgsType } from '@nestjs/graphql';
2+
import { Type } from 'class-transformer';
23
import { Field } from '../decorators/field.decorator';
34

45
@ArgsType()
56
export class PaginationArgs {
7+
@Type(() => Number)
68
@Field({
79
name: 'skip',
810
description: 'Number of records to skip (offset based pagination).',
@@ -36,6 +38,7 @@ export class PaginationArgs {
3638
})
3739
before?: string;
3840

41+
@Type(() => Number)
3942
@Field({
4043
name: 'first',
4144
description: 'Max number of items to return going forward from the cursor.',
@@ -47,6 +50,7 @@ export class PaginationArgs {
4750
})
4851
first?: number;
4952

53+
@Type(() => Number)
5054
@Field({
5155
name: 'last',
5256
description: 'Max number of items to return going backward from the cursor.',

0 commit comments

Comments
 (0)