如何在模型中编写多个远程方法?

时间:2016-08-02 10:37:04

标签: javascript node.js loopbackjs strongloop loopback

可能有点棘手,或者我太愚蠢了。每个documentation和示例都说明了如何编写远程方法,但不是多个。在我的情况下,我已经编写了一个远程方法,它的工作完美。

module.exports = function(customer) {
    customer.signup = function(data, cb) {
        customer.create(data, function(err, response){
            cb(err, response);    
        });
    };

    customer.remoteMethod(
        'signup',
        {
        accepts: [{arg: 'data', type: 'object', http: { source: 'body' }}],
        returns: {type: 'object', root: true}
        }
    );
};

当我尝试添加另一个远程方法时,它不能按要求工作,可能是由于某些语法错误。

module.exports = function(customer) {
    customer.signup = function(data, cb) {
        customer.create(data, function(err, response){
            cb(err, response);    
        });
    };

    customer.remoteMethod(
        'signup',
        {
        accepts: [{arg: 'data', type: 'object', http: { source: 'body' }}],
        returns: {type: 'object', root: true}
        }
    );

    customer.resetPassword = function (data, cb) {
      console.log(data);
      cb(null, data);
    };
    customer.remoteMethod(
        'resetPassword',
        {
        accepts: [{arg: 'data', type: 'object', http: { source: 'body' }}],
        returns: {type: 'object', root: true}
        }
    );
};

我甚至尝试了一些变体来合并数组等中的remoteMethods声明,但没有一个可行。请建议我不对的地方。

1 个答案:

答案 0 :(得分:1)

您需要指定它们的路径。

<description>
   <number> ## </umber>
   <building> XYZ </building>
   <street> XXX </street>
   <town> YYY </town>
   <postcode> #### </postcode>
</description>