Skip to content

Instantly share code, notes, and snippets.

@sicruse
Created May 15, 2017 22:41
Show Gist options
  • Select an option

  • Save sicruse/bfaa17008990bab2fd1d76a670c3923f to your computer and use it in GitHub Desktop.

Select an option

Save sicruse/bfaa17008990bab2fd1d76a670c3923f to your computer and use it in GitHub Desktop.

Revisions

  1. sicruse created this gist May 15, 2017.
    33 changes: 33 additions & 0 deletions messages.hooks.js
    Original 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 {
    ...
    }
    };