Skip to content

Commit

Permalink
🐛 Implement implicit casting for dto
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed Feb 7, 2024
1 parent 6817afa commit 30522d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/common/models/dto/id.dto.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {ApiProperty} from "@nestjs/swagger";
import {IsNotEmpty} from "class-validator";
import {Type} from "class-transformer";
import {IsInt, IsNotEmpty} from "class-validator";

export class IdDto{
@ApiProperty()
@IsNotEmpty()
@Type(() => Number)
@IsInt()
id: number;
}
7 changes: 5 additions & 2 deletions src/common/pipes/custom-validation.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ export class CustomValidationPipe extends ValidationPipe{
private readonly logger = new Logger(CustomValidationPipe.name);

constructor(){
super({transform: true});
super({
transform: true,
transformOptions: {enableImplicitConversion: true}
});
}

createExceptionFactory(){
Expand All @@ -16,7 +19,7 @@ export class CustomValidationPipe extends ValidationPipe{
property: error.property,
constraints: error.constraints,
}));
this.logger.error(messages);
// this.logger.error(messages);
return new BadRequestException(messages);
};
}
Expand Down

0 comments on commit 30522d9

Please sign in to comment.