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

Usage of feathers common hook in custom hook #642

Closed
barbeblanche96 opened this issue Sep 9, 2021 · 1 comment
Closed

Usage of feathers common hook in custom hook #642

barbeblanche96 opened this issue Sep 9, 2021 · 1 comment

Comments

@barbeblanche96
Copy link

barbeblanche96 commented Sep 9, 2021

Hello, does it possible to use these common hooks in a custom generate hook?

I try this but doesn't work.

const {preventChanges} = require('feathers-hooks-common');  
module.exports = (options = {}) => {
  return async context => {

    if(context.method === 'patch'){
      preventChanges(true, 'type');
    }
    return context;
  };
};
@daffl
Copy link
Member

daffl commented Sep 14, 2021

It needs to be called with the context and also add an await in case it is asynchronous:

const {preventChanges} = require('feathers-hooks-common');  
module.exports = (options = {}) => {
  return async context => {

    if(context.method === 'patch'){
      await preventChanges(true, 'type')(context);
    }
    return context;
  };
};

@daffl daffl closed this as completed Sep 14, 2021
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