class-validator icon indicating copy to clipboard operation
class-validator copied to clipboard

Validation not working on Partial class

Open ilmcraft opened this issue 7 years ago • 3 comments

In nestjs If I use dto class as Partial validation not applying to any column. I mean validation totally not working!

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);
}

ilmcraft avatar Apr 16 '19 13:04 ilmcraft

I would really like this one too...

nolazybits avatar May 22 '19 02:05 nolazybits

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.

vlapo avatar Jun 13 '19 22:06 vlapo

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.

lock[bot] avatar Jun 20 '19 23:06 lock[bot]