21

I have

epilogue.resource({
  model: db.Question,
  endpoints: ['/api/questions', '/api/questions/:id'],
  associations: true
});

So when I hit /api/questions, I get back all the associations with the resources. Is there something I can pass to not get the associations in certain cases? Or should I create a new endpoint:

epilogue.resource({
  model: db.Question,
  endpoints: ['/api/questions2', '/api/questions2/:id']
});
Maxime Rouiller
  • 13,614
  • 9
  • 57
  • 107
Shamoon
  • 41,293
  • 91
  • 306
  • 570
  • Maybe this commit does what you are looking for: [Allow not reading associations on read](https://github.com/dchester/epilogue/pull/122) – dafyk May 04 '16 at 20:45

1 Answers1

1

One way of doing is by using milestones you can define milestone for list and read behaviour in certain case, you have access to req object so you can do changes accordingly

https://github.com/dchester/epilogue#customize-behavior

Here is an example of list call modification

// my-middleware.js
module.exports = {
  list: {
    write: {
      before: function(req, res, context) {
        // modify data before writing list data
        return context.continue;
      },
      action: function(req, res, context) {
        // change behavior of actually writing the data
        return context.continue;
      },
      after: function(req, res, context) {
        // set some sort of flag after writing list data
        return context.continue;
      }
    }
  }
};

// my-app.js
var epilogue = require('epilogue'),
    restMiddleware = require('my-middleware');

epilogue.initialize({
    app: app,
    sequelize: sequelize
});

var userResource = epilogue.resource({
    model: User,
    endpoints: ['/users', '/users/:id']
});

userResource.use(restMiddleware);
Keval
  • 3,246
  • 20
  • 28