nestjs-paginate
nestjs-paginate copied to clipboard
Serialize the data array
Original: https://github.com/ppetzold/nestjs-paginate/issues/72#issuecomment-908314018
With serialization, I mean filtering and transforming the response data. Using class-transformer, for example.
For now, in my code, I have implemented an interceptor (also could be a class or helper function) to catch the Paginated and call the
plainToClass()
for data param. Here I can provide a small example for the better understanding:// controller const paginatedResults = await paginate(...) // Item[] return { ...paginatedResults, data: plainToClass(ItemResponseDto, paginatedResults.data) }
// ItemResponseDto with class-transformer @Exclude() export class ItemResponseDto { @Expose() id: string; ... }
Having written this, I think this logic should be the responsibility of this module. So, nevermind 😅
I was able to workaround that using the following code
Yup. That would be an example for the query builder solution I was referring to in #114
This issue here tho refers more to the incorporation of all feature of class-transformer. Besides hiding/exposing properties, it has decorators for additional data transformation etc.