-
Notifications
You must be signed in to change notification settings - Fork 10
Conversation
This is great, thank you! I was actually thinking about doing the same thing for #853. I'm not sure if the converters are needed. I was going to put the arguments array for unknown methods into |
I chose the simplest solution, the one used internally but it's true that converters can easily be translated from I do not know where exactly you would like to declare |
Do you think of something like this? const app = feathers().use('/dummy', {
methods: {
custom: ['id', 'data', 'params']
},
get() {},
// ...
custom(id, data, params) {
return Promise.resolve([id, data, params]);
}
});
app.service('dummy').hooks({
before: {
all: [/**/],
custom: [/**/]
},
after: {
all: [/**/],
custom: [/**/]
}
});
return app.service('dummy').custom(28, { bar: 'foo' }, { provider: 'rest' }); or const app = feathers().use('/dummy', {
methods: ['custom'],
get() {},
// ...
custom(id, data, params) {
return Promise.resolve([id, data, params]);
}
});
app.service('dummy').hooks({
arguments: {
custom: ['id', 'data', 'params']
}
before: {
all: [/**/],
custom: [/**/]
},
after: {
all: [/**/],
custom: [/**/]
}
});
return app.service('dummy').custom(28, { bar: 'foo' }, { provider: 'rest' }); |
I have updated the first example. |
What I mean is that app.hooks({
before: {
myMethod(context) {
const [ id, data, something ] = context.arguments;
return Object.assign(context, {
id, data, something
});
}
}
}); In fact, I just realized that we might not need converters at all since the same can totally be done in the already existing argument validation hook (https://github.com/feathersjs/feathers/blob/master/lib/hooks.js#L47) for the normal service methods. |
I do not see exactly what changes I should make based on your comment, can you point me? |
I'll merge this one and then will update it accordingly. |
I have updated this and feathersjs/feathers#864. |
I deleted converters, it's a hook that is just after |
This looks great, thank you! I'll get this one in and then verify it against feathersjs/feathers#864 |
This PR allows you to add converters to your custom methods, which allows to create the hook corresponding to your arguments and finally to fully use the hook workflow.
I would have liked to use a Symbol but feathersjs/feathers#863.
Example: