0

I'm trying to add validation to the param I get in the request for example to delete something. The param is a string but it has to be a valid UUID. I added the dto to the type of the param in the controller.

@Delete(':personId')
  async deletePersonIdentity(@Param('personId') id:deletePersonIdentityDto) {
    return this.personIdentityService.deletePersonIdentity(id.personId);
  }

The DTO for deletePersonIdentity looks like this.

export class deletePersonIdentityDto {  
  @ApiProperty({
    example: 'fd914b72-a423-4256-99a1-aff78da9281f',
    description: `ID of the Person`,
    required: true,
  })
  @IsUUID()
  readonly personId: string;
}

Even if I pass a valid UUID in the param I still get a bad request that says that the id must be a UUID. This is the error thrown by the class-validator. Any ideas?

John Shelby
  • 87
  • 2
  • 9

1 Answers1

1

The req.params['personId'] (what @Param('personId') maps to) does not satisfy the type deletePersonIdentityDto. What you're looking for is @Param() { personid }: deletePersonIdeentiyDto which is equivalent to const { personId } = req.params

Jay McDoniel
  • 57,339
  • 7
  • 135
  • 147