1.0.5 • Published 5 years ago

feathers-include-hook v1.0.5

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

feathers-include-hook

Hooks for include before

context => {
  const sequelize = context.app.get('sequelizeClient');
  const { myModel, anotherModel, singleModel } = sequelize.models;
  
  const raw = false;

  context.params.sequelize = {
    include: [
      {
        model: myModel,
        as: 'MyModels',
        where: {
          smth: 'likeSmth'
        },
        include: [anotherModel]
      },
      singleModel
    ]
  }
  return context;
}

And now:

First of all install the package

npm i --save feathers-include-hook

And then

const include = require('feathers-include-hook');

module.exports = {
  before: {
    find: [
      include([
        {
          model: 'myModel',
          as: 'MyModels',
          where: {
            smth: 'likeSmth'
          },
          include: [
            {
              model: 'anotherModel',
              context: {
                where: {
                  idField: '$params.user.id'
                }
              }
            }
          ]
        },
        'signleModel'
      ])
    ]
  }
};

You can use just a string instead of imported model

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago