-
-
Notifications
You must be signed in to change notification settings - Fork 797
Closed
Milestone
Description
Steps to reproduce
If you need before hooks to run after all services, you'd have to copy paste the hook to every single service, or hack it into an extended adapter.
Solutions:
- add applications hooks: afterBefore, beforeAfter, beforeError that can handle the reverse scenario.
- make the cli generate apps with a hook filter on the service that can facility support for these cases. Hook middleware in a way.
My current solution:
Usage in service: service.hooks(proxyHooks(hooks))
// Application hooks that run for every service
const proxiedHooks = {
before: {
all: [],
find: [],
get: [],
create: [ ],
update: [ ],
patch: [ ],
remove: []
},
after: {
all: [ ],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},
error: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
}
}
modules.exports = function proxyHooks (hooks) {
for (const baeK of Object.keys(hooks)) {
const cruds = hooks[baeK]
for (const crudK of Object.keys(cruds)) {
const hook = cruds[crudK]
if (Array.isArray(hook)) {
cruds[crudK] = baeK === 'before'
? [...hook, ...proxiedHooks[baeK][crudK]]
: [...proxiedHooks[baeK][crudK], ...hook]
}
}
}
return hooks
}
Conversation that inspired this: https://pastebin.com/fQh43HhT
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels