You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, there is a bug involved when using the class-transformer package which is mentioned in the documentation, the official nestJS ClassSerializerInterceptor and this library.
The interceptor works on a single entity, on an array of entities, but not from a default paginated object - which leads me to believe this is not intended behaviour.
In the source code for this codebase to create a page, a plain object is sent back, and since the entities are nested inside the data param, they are never transformed because their parent object does not pass the classToPlain check:
Changing the page method to return some class instance which implements the GetManyDefaultResponse interface should be enough to fix it without breaking changes, otherwise a nest interceptor that uses a typescript runtime guard to check if the response object follows the interface could be used but it would require users to wire it up.
The text was updated successfully, but these errors were encountered:
Same issue exists for updateOne method. I was able to bypass it by using query.allow to include only needed fields, but it's indeed a weird behavior that ClassSerializerInterceptor works for getOne or getMany, and doesn't work for updateOne and other methods.
Would be extremely useful to have a list of entity public fields in one place, not two.
PS. This package is great anyway, thanks for creating it :)
I've added CrudSerializeInterceptor (applies automatically) along with the new CrudOption serialize where you can provide separate response dtos for each route (action), and if there is no dto provided for a particular action the model type will be used.
Also, all action methods in TypeormCrudService return an entity instance, no plain objects. So, serialization now works. Please try 4.3.0-beta versions. The documentation will be added soon
Hello, there is a bug involved when using the
class-transformer
package which is mentioned in the documentation, the official nestJSClassSerializerInterceptor
and this library.The interceptor works on a single entity, on an array of entities, but not from a default paginated object - which leads me to believe this is not intended behaviour.
In the source code for the interceptor, you'll see it does a check to see if the constructor of the item being passed in is an
Object
and if not, it will serialize : https://github.com/nestjs/nest/blob/b4baa995e43c77ef169585943bab0c21f31af418/packages/common/serializer/class-serializer.interceptor.ts#L66In the source code for this codebase to create a page, a plain object is sent back, and since the entities are nested inside the
data
param, they are never transformed because their parent object does not pass theclassToPlain
check:crud/packages/crud/src/services/crud-service.abstract.ts
Line 29 in 06b5d46
Changing the page method to return some class instance which implements the
GetManyDefaultResponse
interface should be enough to fix it without breaking changes, otherwise a nest interceptor that uses a typescript runtime guard to check if the response object follows the interface could be used but it would require users to wire it up.The text was updated successfully, but these errors were encountered: