Reputation: 5677
I want to implement an after-hook that replaces record IDs with globally unique IDs of the form {serviceName}:{id}
(where id
is a typical MySQL numerical ID).
However I couldn't find a way to access serviceName
or service mount point from hooks. Is it possible?
If not, I'll just stick with passing the service name as a parameter during hook instantiation, but that's manual and error prone. I expect there's a better way to do this :)
Upvotes: 0
Views: 293
Reputation: 44215
You can iterate over all services and then return the path for the one that matches the hook context:
app.service('myservice').before({
create(hook) {
const service = this;
const allServices = hook.app.services;
const path = Object.keys(allServices).find(
currentPath => allServices[currentPath] === service
);
}
});
Upvotes: 1