To anyone familiar with NestJS, is there a happy m...
# orm-help
a
To anyone familiar with NestJS, is there a happy medium between the Prisma generated types and a class validator to verify your input data? Most examples I've seen you either use the Prisma generated types or you create a DTO that uses
class-validator
.
1
k
What do you mean exactly?
j
n
zod-prisma
is a good choice if you want to define your validations in
schema.prisma
file.
❤️ 1
o
You could also use a validation library(like Joi, Yup, Class Validator, Zod) + a Prisma generator. That way you have full CRUD validations. Here's a rundown of the available generators in the community that handles validation: •
zod-prisma
produces top level model schemas(if you have two models in prisma schema, you get two schemas written in Zod). •
prisma-zod-generator
produces full CRUD schemas using Zod. •
prisma-joi-generator
produces full CRUD schemas using Joi. •
prisma-yup-generator
produces full CRUD schemas using Yup. •
prisma-class-validator-generator
produces top level classes that are validated using Class Validator's decorators
👍 2
a
@Kasir Barati When you're using prisma, from what I've seen, people generally use a class DTO along with the class-validator lib to make sure the proper data is sent with a request and is validated. However prisma also auto generates a bunch of types for you based on your schema. So if you have a Post with title, and description, with typescript you can say that the incoming body data has to have those fields,
body: Prisma.PostWhereUniqueInput
or something along those lines. If you took the DTO route you'd do something like
body: CreatePostDto
and this would be something you write out by hand and maintain. I was just wondering what the best practice was between the generated Prisma types and defining your own DTOs.
I'll checkout the zod-prisma lib suggested here