Skip to content

Instantly share code, notes, and snippets.

@JayBee007
Forked from sicruse/messages.hooks.js
Created November 21, 2018 19:55
Show Gist options
  • Save JayBee007/291ce1536d34af64db60b14608e95e14 to your computer and use it in GitHub Desktop.
Save JayBee007/291ce1536d34af64db60b14608e95e14 to your computer and use it in GitHub Desktop.
Example use of feathers-sequelize object hydration
const hydrate = require('feathers-sequelize/hooks/hydrate');
function includePoster() {
return function (hook) {
const model = hook.app.service('users').Model;
const association = { include: [{ model: model, as: 'poster', attributes: ['userId', 'displayName', 'avatar'] }] };
switch (hook.type) {
case 'before':
hook.params.sequelize = Object.assign(association, { raw: false });
return Promise.resolve(hook);
break;
case 'after':
hydrate( association ).call(this, hook);
break;
}
}
}
module.exports = {
before: {
all: [ includePoster() ],
...
},
after: {
all: [ includePoster() ],
...
},
error {
...
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment