Open
Description
Is there a way to use the softDelete
hook for batch requests?
I found out deleting multiple records at once via batch remove does nothing, the workaround is simply making multiple (individual) remove calls.
Steps to reproduce
// DOES NOT WORK: batch/multi-remove by softDelete()
app.service('files').remove(null, params)
// WORKS: less-performant workaround
const files = await app.service('files').find({
...params,
paginate: false
})
await Promise.all(files.map(({ _id ) => app.service('files').remove(_id)))
The softDelete
hook is configured as follows:
softDelete({
// returns query object to spread in query
deletedQuery: async (ctx: HookContext) => {
const param = ctx.params.query?.deletedAt
const isTruthy = ['true', true].includes(param)
return { deletedAt: truthy ? { $ne: null } : null}
},
// returns patch data to spread in data for remove
removeData: async (ctx: HookContext) => ({ deletedAt: new Date().toISOString() })
})
Expected behavior
Files should be set to new Date().toISOString()
when deleting one, or multiple in batch.
Actual behavior
Only files deleted individually are set to new Date().toISOString()
.
Metadata
Metadata
Assignees
Labels
No labels