#Better way of implementing Queries at controller level? (im using Prisma)
17 messages · Page 1 of 1 (latest)
Better... How? What are you looking to optimize here?
I mean like, is this the typical way to implement querying when working with NestJS and prisma ?
Is it like the cleanest way i mean
If thats the cleanest way to set it up, I would probable hide the logic above in a function and just call it in the controller, just to keep it s bit cleaner
Idk if my question makes sense
Personally I'd probably pass the entire query object on to the service and do any manipulation there. Thin controllers, fat services.
I probably would use a function to abstract out the logic as well. I don't know how prisma handles undefined, but if it just ignores it then you could simply do filters = { city, propertyType, price } with only the price have any assignment logic around it
Gotcha, i was also planning out to just pass this logic to the service and thats all
I also like to keep my controllers lean
You could also get all the query vals at once using @Query() query: Type
Oh so like with the help of an interface ?
Interface, DTO class that can be validated, Typescript type, yeah