#IsUUID decorator does not pass uuid value

3 messages · Page 1 of 1 (latest)

wild terrace
#

Hello friends, could you please help me? I searched solution at SO but I can't find it.
I'm using class-validator v0.14.1 with nestjs 10.
In main faile I've got app.useGlobalPipes(new ValidationPipe());

my DTO:

export class GetCustomerDetailsQueryDto {
  @ApiProperty({
    type: 'string',
    format: 'uuid',
  })
  @IsUUID()
  id: string;
}

and controller method:

@Get('details')
  @ApiResponse({
    status: 200,
    description: 'Details for selected customer',
    type: CustomerDetailsDto,
  })
  @ApiResponse({
    status: 400,
    description: 'Validation error',
    type: RequestValidationError,
  })
  @ApiResponse({
    status: 404,
    description: 'Not found',
    type: String,
  })
  @ApiResponse({ status: 500, description: 'Internal server error' })
  async getCustomerDetailsById(
    @Query('dto') dto: GetCustomerDetailsQueryDto,
  ): Promise<CustomerDetailsDto> {
    return this.queryBus.execute(new GetCustomerDetailsQuery(dto.id));
  }

in this case I always getting an error 400 "id must be a UUID".

What's going on? I never had problem with that...

south pelican
#

Use @Query() not @Query('dto')

wild terrace
#

You're my god. Thanks so much. I'm dump 🤦🏻‍♂️