如何在loopback js中覆盖update(put)方法

时间:2016-10-21 18:21:35

标签: loopbackjs

基于环回文档,我们可以覆盖远程方法。我想覆盖PUT : /products/{id}个请求。

我试试这个:

module.exports = function (product) {
    product.save = function(data,callback){
        callback();
    }
};

我尝试使用:updateupdateAttributesupsert以及所有相关方法,但仍无效...

虽然覆盖了create方法,但update没有!

有什么建议吗?

2 个答案:

答案 0 :(得分:0)

使用product.prototype可以触发put这样的请求:

product.prototype.updateAttributes = function (data,callback) {
    console.log('updateAttributes');
    callback();
};

答案 1 :(得分:0)

如果要禁用API端点,可以使用以下命令

Product.disableRemoteMethod('update', true)
Product.disableRemoteMethod('updateAttributes', true)
Product.disableRemoteMethod('upsert', true)

文档链接 - https://docs.strongloop.com/display/public/LB/Exposing+models+over+REST#ExposingmodelsoverREST-Exposingandhidingmodels,methods,andendpoints