9

I have a basic controller setup:

@Controller('')
export class AController {
 @Get(':id')
  async getThing(@Param('id', ParseUUIDPipe) id: string): Promise<RegisterRead[] | IntervalRead[]> {
      return id
  }
}

And I get the following error:

{
    "statusCode": 400,
    "error": "Bad Request",
    "message": "Validation failed (uuid vundefined is expected)"
}

Also see: https://github.com/nestjs/nest/issues/2960

2 Answers 2

12

This issue was caused because I did not have a version specified. It shows version as an optional field, but it appears to be required:

new ParseUUIDPipe({version: '4'})
2
  • 1
    could you accept your own answer - if you can - please ? :)
    – A. Maitre
    Dec 27, 2019 at 9:53
  • 3
    Just an update to this - the version is apparently no longer required, and @Param('id', ParseUUIDPipe) id: string should work
    – robertmain
    Jul 16, 2021 at 22:25
1

With decorator helper:

import { Param, ParseUUIDPipe } from '@nestjs/common';

export const UUIDParam = (name: string) => Param(name, new ParseUUIDPipe());

// Your controller endpoint
@Patch(':id')
public async updateOne(@UUIDParam('id') id: string): any;

📌 Docs link here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.