Closed Hareloo closed 11 months ago
how your http request looks like?
how your http request looks like?
For example: https://localhost:4001/api/v2/patients Just not specifying the param
Perhaps similarly to boolean parameters, we should skip the primitives transformation when value === undefined?
Perhaps similarly to boolean parameters, we should skip the primitives transformation when value === undefined?
I believe something like that would solve this.
Would you like to create a PR for this issue?
Would you like to create a PR for this issue?
Sure! I'll get on it soon.
Created a PR for this here: https://github.com/nestjs/nest/pull/12893
Let's track this here https://github.com/nestjs/nest/pull/12893
This problem is still not solved yet, my solution is:
// pipes/int-default-value-pipe.ts
import { PipeTransform, Injectable, ArgumentMetadata } from '@nestjs/common';
@Injectable()
export class IntDefaultValuePipe implements PipeTransform {
constructor(private readonly defaultValue: any) {}
transform(value: string, metadata: ArgumentMetadata): any {
const val = parseInt(value, 10);
return isNaN(val) ? this.defaultValue : val;
}
}
Then put the original code:
@Query('page') page = 0
Change it to this:
@Query('page', new IntDefaultValuePipe(0)) page
It working.
No solution for this ?
We encounter this problem too . When we use :
app.useGlobalPipes(
new ValidationPipe({
transform: true,
}),
);
..it corrupts our @Query
default param values to NaN
.
We would like to keep the clean writing: @Query('page') page = 0
for our query parameters so we dont use the @luzhenqian's solution.
Is there an existing issue for this?
Current behavior
I am using a ValidationPipe enabled globally with
transform: true.
. The problem is that I have query params which are optional, or that should have a default value if not explicitly set, like so:The issue is that both
limit
andoffset
get converted to NaN when no value is passed, instead of to the default value I set. If I try to change the code so that these params will be optional like so:The same issue persists...
Minimum reproduction code
https://stackblitz.com/edit/nestjs-typescript-starter-mgxaub?file=src%2Fapp.controller.ts,src%2Fmain.ts
Steps to reproduce
No response
Expected behavior
Package
Other package
No response
NestJS version
^10.0.0
Packages versions
Node.js version
20.10.0
In which operating systems have you tested?
Other
No response