I'm trying to use Prisma with ValidationPipe that NestJS provides but it is not working, I was using class-validator
package with DTO's (classes) as ValidationPipes
and it was working fine, now I need a way to use the same pattern with Prisma without the need of DTOs to not have duplicated types. (I want to avoid creating custom pipes for validation)
DTO FILE:
import { IsNotEmpty } from 'class-validator';
export class TodoCreateDto {
@IsNotEmpty()
title: string;
@IsNotEmpty()
description: string;
}
WITH DTO: working
@Controller('todos')
export class TodosController {
constructor(private todosService: TodosService) {}
@Post()
@UsePipes(ValidationPipe)
createTodo(@Body() todoCreateDto: TodoCreateDto) {
return this.todosService.createTodo(todoCreateDto);
}
}
WITH PRISMA: not working
@Controller('todos')
export class TodosController {
constructor(private todosService: TodosService) {}
@Post()
@UsePipes(ValidationPipe)
createTodo(@Body() todoCreateInput: Prisma.TodoCreateInput) {
return this.todosService.createTodo(todoCreateInput);
}
}