Created
May 15, 2017 22:41
-
-
Save sicruse/bfaa17008990bab2fd1d76a670c3923f to your computer and use it in GitHub Desktop.
Revisions
-
sicruse created this gist
May 15, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ 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 { ... } };