Provide default value for querystring param with pipes on NestJS

Viewed 1820

I'm trying to implement this example. It looks so simple to implement but I have some troubles.

@Get('test')
async test(
  @Query('size', new DefaultValuePipe(10), ParseIntPipe) size: number,
  @Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number,
) {
   // Do some stuff
}
  • The first request I've made is http://localhost/api/test
    • The requests I sent without params are replied with 400 Bad Request and the message is Validation failed (numeric string is expected).
  • The second request I've made is http://localhost/api/test?size=&page=
    • The requests I sent with empty params are passed as 0, not with the value that I want to be provided by default.

In both requests, the default values are expected to pass, right? If so, what am I doing wrong?

0 Answers
Related