exclude fields on post, put request in epilogue

380 Views Asked by At

I am using expressjs with sequalize ORM. My user model is some what like

module.exports = function (sequelize, DataTypes) {
 var User = sequelize.define('user', {
    userName: {
      type: DataTypes.STRING
    },
    isAdmin: {
      type: DataTypes.Boolean
    }
   })
  }

but I dont want to allow the request to set isAdmin to be set to true or false on POST/PUT. But i want isAdmin on get request.

I know about excludeAttributes property but it removes the fields on GET request only.

1

There are 1 best solutions below

1
Satyajeet On BEST ANSWER

You need to set the readOnlyAttributes. This feature is yet not included in published release. However you can use it by changing your epilogue version to dchester/epilogue#master in package.json. Sample code might look like

var rest = require('epilogue')
var userResource = rest.resource({
   model: DB.User,
   readOnlyAttributes: ['isAdmin']
});

See this Pr.