risen228 / nestjs-zod-prisma

Zod Prisma fork for nestjs-zod
MIT License
62 stars 11 forks source link

How to adjust generated DTO, for example exclude auto incremented ID property? #10

Closed shwarcu closed 1 year ago

shwarcu commented 1 year ago

Hi, I have following prisma model and auto generated Zod object image

I am trying to use it when adding a new Article. But generated DTO has id property as optional. Prisma client expects id to never exist. How should I handle this?

I am able to use Omit to handle just the issue of id property but then it creates another issues, for example that title is optional in my DTO but it's required by prisma model.

I am looking for optimal way of handling this, so that I don't have to create multiple classes, types or interfaces.

Edit: I see that type inferred from Zod, gives my optional title property, while it should be required. Is there a way around this? image