Reputation: 217
I'm trying to create a FeathersJS hook that returns a boolean value to use inside the iff() hook of the "feathers-hooks-common" package. Something like the isProvider() hook of the same package.
My problem is that I'm using the TypeScript version of the feathers cli generated app and when I use the generator to create a new hook, the result is:
// Use this hook to manipulate incoming or outgoing data.
// For more information on hooks see: http://docs.feathersjs.com/api/hooks.html
import { Hook, HookContext } from '@feathersjs/feathers';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export default (options = {}): Hook => {
return async (context: HookContext): Promise<HookContext> => {
console.log(context);
return context;
};
};
so I don't know how can I use this generated typescript code to return a boolean value that can be used in the iff() hook.
Is there anyone that knows how to do this?
Thank you!
Upvotes: 1
Views: 297
Reputation: 217
if anybody needs it, I've used this code to return a boolean value in a hook:
// Use this hook to manipulate incoming or outgoing data.
// For more information on hooks see: http://docs.feathersjs.com/api/hooks.html
import { HookContext } from '@feathersjs/feathers';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export default (options = {}) => {
return async (context: HookContext): Promise<boolean> => {
//Do whatever you need with context data
return a_boolean_value;
};
};
I don't know if this would be "the FeathersJS way" but it works.
Upvotes: 1