内置StrongLoop覆盖PUT的方法 [英] StrongLoop overriding PUT built in method

查看:107
本文介绍了内置StrongLoop覆盖PUT的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,试图覆盖PUT请求的内置方法StrongLoop.

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

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

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');
    }; 
}

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

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');
}

感谢您的帮助.

推荐答案

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

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: '/'
  }
});

这篇关于内置StrongLoop覆盖PUT的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆