简体   繁体   中英

exclude fields on post, put request in epilogue

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM