I have a NestJS app where I need to define entities (classes that serve as Mongoose schemas) and DTOs (classes that define the API request/response shapes).
There are times where these 2 classes are nearly identical, like when you need to create a new resource.
It would be nice if I could easily reuse whatever parts I need from the Mongoose schema, remove the schema-specific decorators and then add Swagger/DTO-specific decorators.
I think something like this might be possible with class-transformer
but I’m not sure. I’m also not sure if it’s even a good idea to reuse these classes in this way (in order to avoid accidentally exposing something from your db to the outside world that you shouldn’t)