Skip to content

Commit

Permalink
Proposal to bring back the access another service from inside a hook
Browse files Browse the repository at this point in the history
A common scenario is we need to access another service from inside the hook, I propose to revive a legacy documentation found on this issue feathersjs/feathers#382
  • Loading branch information
tuxrace committed Oct 11, 2017
1 parent 9dcf471 commit b29991e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions api/hooks.md
Expand Up @@ -245,3 +245,28 @@ app.hooks({
}
});
```

## Access another service from inside a hook

To access a feathers service from inside a hook using ```hook.app.service('servicename')```

The following example we access the ```users``` service from within the message service hook

```js
app.service('messages').hooks({
after: {
create: [
function(hook) {
// We access another service called hook.app.service('users') and fun the create function
return hook.app.service('users').create(hook.data,{}).then(user => {
// Update the result (the message)
hook.result.user = user;

// Returning will resolve the promise with the `hook` object
return hook;
});
}
]
}
});
```

0 comments on commit b29991e

Please sign in to comment.