Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Proposal documentation to bring back the access another service from inside a hook. #866

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions api/hooks.md
Original file line number Diff line number Diff line change
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;
});
}
]
}
});
```