Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support batch remove when using softDelete() hook #701

Open
miguelrk opened this issue Jan 6, 2023 · 1 comment
Open

Support batch remove when using softDelete() hook #701

miguelrk opened this issue Jan 6, 2023 · 1 comment

Comments

@miguelrk
Copy link

miguelrk commented Jan 6, 2023

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().

@fratzinger
Copy link
Collaborator

I never used the softDelete hook myself. On my setups, feathers-sequelize handles this out of the box.

So I'm not planning to work on that but a PR is highly appreciated.

Please let me know, if you're up to work on this and also contact me, if you need guidance. 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants