ppetzold / nestjs-paginate

Pagination and filtering helper method for TypeORM repositories or query builders using Nest.js framework :book::paperclip:
MIT License
398 stars 88 forks source link

Possibility to control soft deleted records in query parameter like "withDeleted" ? #940

Open webdevog opened 1 week ago

webdevog commented 1 week ago

Hello! Firstly, thank you for the great library and your work! I need to control response by a filtering parameter like "withDeleted", so I can show to a user active records and deleted records depending on a some filter parameter (something like "withDeleted" or so on). So that user can restore deleted items etc. Can you please tell me the correct way to control withDeleted results? Thank you!

Helveg commented 1 week ago

I think this should be possible with the where: { deletedAt: null }/where: { deletedAt: Not(null) } in the configuration?

webdevog commented 1 week ago

@Helveg thanks for your response, but again your proposal - it is kind of global filtering in configuration. We can achieve this using withDeleted: true or withDeleted: false in configuration.

I'd like to have withDeleted: false by default. So that - only active records are being returned in many places in my application, but in specific cases - for admin user purposes I'd like to specify some query parameter to return not only active records but deleted records (soft deleted to be precise) as well.

ppetzold commented 1 week ago

just pass your "custom query param" to the withDeleted config then ? 😅

webdevog commented 1 week ago

@ppetzold thank you. For sure it will work, but I thought that it would be a nice feature to have it in a predefined set of parameters because I think it can be commonly used. Anyway thank you, at least now I know that it is not build-in feature and I need to create my custom query parameter

webdevog commented 1 week ago

Ok. I made such a solution without using any custom parameters: findAll(query: PaginateQuery): Promise<Paginated<Facility>> { FACILITY_PAGINATE_CONFIG.withDeleted = query?.filter?.deletedAt === '$not:$null'; return paginate(query, this.r, FACILITY_PAGINATE_CONFIG); }