JKHeadley / rest-hapi

🚀 A RESTful API generator for Node.js
https://resthapi.com
MIT License
1.19k stars 153 forks source link

Shouldn't pagination exclude deleted items? #235

Closed yoieh closed 4 years ago

yoieh commented 4 years ago

Is your feature request related to a problem? Please describe. Do not know it this is a bug or not so I'm adding it here.

When soft delete is active shouldn't total items exclude deleted items? If not its impossible to tell how many items actually "exists" on a clients pagination.

Describe the solution you'd like exclude isDeleted documents from the total amount also recalculate the total amount of pages based of the new total amount.

Describe alternatives you've considered An other solution would be to return total isDeleted amount as its own value in items as items.deleted but only if the total soft delete is activated. Then on the client side you could recalculate the number of pages as such pages.total = Math.ceil(item.total - item.deleted / item.limit)

JKHeadley commented 4 years ago

@yoieh Thanks for bringing this up. Soft delete is a tricky feature to manage and I'm definitely open to ideas. For your needs I think the current solution would be to select documents with isDeleted equal to false within the query itself, like so:

http://localhost:8080/permission?$page=2&$limit=10&isDeleted=false

This will give you proper pagination values excluding deleted documents. Does this make sense?

yoieh commented 4 years ago

In my case I still need the deleted documents to be able to remove them from the client. But yes i went with a costume rout as a "sync route". That takes a lastSync=DATE. Then I'm doing the "get list" call with isDeleted=false. Not really optimal to do to calls every time an client updates but it works and also enables an case to update cached documentss on my client. Still there are some other problems with the amount of data that could be receiving buy a new user.. this what's why I needed a way to just know the amount of deleted items of the total.

JKHeadley commented 4 years ago

@yoieh lets move the conversation to your PR: https://github.com/JKHeadley/rest-hapi/pull/236