class-validator
class-validator copied to clipboard
Validation not working on Partial class
In nestjs If I use dto class as Partial
user.dto.ts
import { IsString, IsNotEmpty, IsEmail } from "class-validator";
export class UserDTO {
@IsNotEmpty()
@IsString()
readonly name: string;
@IsEmail()
readonly email: string;
@IsNotEmpty()
@IsString()
readonly password: string;
}
user.controller.ts
@Put(':id')
@UsePipes(new ValidationPipe())
update(@Param('id') id: string, @Body() data: Partial<UserDTO>) {
Logger.log(data, "PRODUCT_CONTROLLER_UPDATE")
return this.userService.update(id, data);
}
I would really like this one too...
I think this is issue for nestjs and class-transformer. class-validator just validate input class.
This is problem of transforming body data into Partial<XY> class. Check this https://github.com/typestack/class-transformer#working-with-generics.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.