Closed yoieh closed 4 years ago
Moving the conversation from https://github.com/JKHeadley/rest-hapi/issues/235
I'm still not sure I understand what you are trying to accomplish. Do you just want to know how many documents returned by a query have isDeleted
equal to true? For example, if my query contains isDeleted=false
then the deleted
value should always be 0, correct?
If I have 20 documents stored in a collections using the $limit
parameter the results are returned as "pages". The items.total
shows the total amount of items matched by the query not including the limit.
Lets say I want to show 3 documents on every page that would be $limit=3
but the total would still be 20 where of 5 are deleted.
I still need to show how many items could be shown but I need to exclude the deleted items from the total.
If I use the isDeleted=false
yes they would be excluded from items.total
but the would also be excluded from doc[]
where I still need them to be able to remove them from my offline caching on my client else my client would still think they exists but not existing in the current query.
I need to be able to fetch
->updated local storage
->show matching data
.
When updating my local storage I would like to be able to still remove isDeleted=true
documents as long with updating updated documents.
This is why I figured to returning the amount deleted items of total would be a better idea. Then just recalculating total and number of pages client side.
But as I mentioned I could just do to calls one with just the deleted items and then one without or the other way around.
After some reconsideration I believe having to calls would be a better solution in my case to enable better control and remove unnecessary data in my "list" results.
Just to document thoughts:
Having a custom route
POST sync
would allow me to postoffline updated
docs and return deleted items (deleted after a inputtedlastSynced=DATE
query) to clean my local storage with. Then usingisDeleted=false
to query new data.
closing this and issue #235 ! But Thank you for responding
Edit: isDeleted=false
dosent work if isDeleted is not defined. Creating an item dose not seem to set this.. Don't know if its a bug or if I may do something wrong in my seeding. I will have to set it in the list.pre
middleware until I can make some more test.
There were a problem with my seeding. The soft delete feature needs to be set to true when using RestHapi.create()
solving #235
Using the
countDocuments()
ascount
that being returned asitems.total
but with query{ isDeleted: true }
. This is only run ifconfig.enableSoftDelete = true
. I cant exclude isDeleted items do to client caching of documents with redux I still need them to be able to remove them from my store.Another solution that would work for me could be to do a call where I only return deleted items and then do my "refresh of data call" but I feel like the client should know how many deleted documents that exists inside of the total amount if soft deletion is used.