nestjsx / crud

NestJs CRUD for RESTful APIs
https://github.com/nestjsx/crud/wiki
MIT License
4.04k stars 533 forks source link

Can I use API read DTOs at crud model? #701

Open alexsun8899 opened 3 years ago

alexsun8899 commented 3 years ago

Hi all,

im new to nestjs crud. Wondering if it’s a way to use read Dto at crud models. Really don’t want to expose dB entities as read Dtos to public. Is there a way to extract all query params from a get request and send them to typeorm curd service?

alexsun8899 commented 3 years ago

I meant just wana use some standard features like ordering, selector, filter and pagination. Not considering join feature at all. Expose entity to public is not a good idea and doesn’t fit most of complex project.

rewiko commented 3 years ago

Have you check https://github.com/nestjsx/crud/wiki/Controllers#dto ?

AlexSun98 commented 3 years ago

Have you check https://github.com/nestjsx/crud/wiki/Controllers#dto ?

Yep, but if im not mistaken, the DTO in the above doc is not about READ requests/ GET queries.

What I'm trying to achieve is having both READ DTO and WRITE DTO exposed to public at API end. In order to use filters, selectors and etcs in GET queries, I probably will need to build another layer to translate a query with parameters into an entities' query, and this should be generic and can be reused by all READ DTOs. Not sure if this libaray already have this kind of features, if anyone know it, please give me some clues. thanks.

AlexSun98 commented 3 years ago

read some source code to better understand nestJs CURD. routes overide will be an option if necessary. thanks. I close it.