StrongLoop 覆盖 PUT 内置方法

StrongLoop overriding PUT built in method

我在尝试为 PUT 请求覆盖 ​​StrongLoop 内置方法时遇到问题。

所以在 model.js 我使用的文件中:

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

但是,当我使用 PUT /api/v1/models/1 和有效负载调用端点时,此函数不会执行,但会执行内置函数。我还尝试使用其他函数而不是 updateAttributes 但没有成功,例如:

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

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

谢谢你帮我。

您可以禁用新方法并将新方法附加到同一端点,而不是覆盖该方法,如下所示:

Model.disableRemoteMethodByName('updateAttributes');

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

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