StrongLoop overriding PUT built in method

你说的曾经没有我的故事 提交于 2019-12-25 04:22:12

问题


I am facing an issue trying to override StrongLoop built in method for PUT request.

So in model.js file I am using:

  Model.on('attached', function(){
    Model.updateAttributes = function(data, id, cb){
      cb(null,'This is a overridden method');
    }; 
}

But when I call the endpoint with a PUT /api/v1/models/1 and payload this function does not get executed but the built in one. I also tried to use other function instead of updateAttributes but without any success like for example:

Model.updateAll = function([where], data, cb) {
  cb(null, 'this is a overriden method');
}

Model.create = function(data, cb) {
  cb(null, 'this is overriden method');
}

Thanks for helping me out.


回答1:


Instead of overriding the method, you can disable and attach a new method to the same endpoint as follows:

Model.disableRemoteMethodByName('updateAttributes');

Model.newMethod = function(cb) {
  cb(null, 'new message');
}

Model.remoteMethod('newMethod', {
  returns: {
    arg: 'msg'
  },
  http: {
    verb: 'put',
    path: '/'
  }
});


来源:https://stackoverflow.com/questions/38848987/strongloop-overriding-put-built-in-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!