Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

[Feature Request] Hook to disable multi-update/patch/remove #98

Closed
petermikitsh opened this issue Sep 10, 2016 · 3 comments
Closed

[Feature Request] Hook to disable multi-update/patch/remove #98

petermikitsh opened this issue Sep 10, 2016 · 3 comments

Comments

@petermikitsh
Copy link

A hook that throws an error (a 400 error may be most appropriate) if the id is null for the update, patch, and remove service methods.

This seems generic enough to be valuable to the community at large.

@petermikitsh
Copy link
Author

Something like this:

const errors = require('feathers-errors');

function disableMultiRecordChange() {
  return function (hook) {
    if (!hook.id) {
      throw new errors.BadRequest('Multi-record changes are not permitted.');
    } else {
      return hook;
    }
  };
}

@daffl
Copy link
Member

daffl commented Sep 10, 2016

It would be a breaking change but I've been wondering about disabling it by default in general. The hook would definitely be the non-breaking way to do this. Only change I'd recommend is to check for hook.id === null since hook.id = 0 would throw a bad request otherwise as well:

const errors = require('feathers-errors');

function disableMultiRecordChange() {
  return function (hook) {
    if (hook.id === null) {
      throw new errors.BadRequest('Multi-record changes are not permitted.');
    } else {
      return hook;
    }
  };
}

If you want to add it (with a small test) in a PR to the new hook collection at https://github.com/eddyystop/feathers-hooks-common that would be great!

@eddyystop
Copy link
Contributor

feathers-hooks-common now has an issue referring to this.

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

No branches or pull requests

3 participants