2016-08-02 19 views
0

Vielleicht ist es ein wenig schwierig oder ich bin zu dumm, um herauszufinden. Jede documentation und Beispiel veranschaulicht, wie eine Remote-Methode geschrieben wird, aber nicht mehrere. In meinem Fall habe ich bereits eine Remote-Methode geschrieben und es funktioniert perfekt.Wie man mehrere Fernmethoden in einem Modell schreibt?

Wenn ich versuche, eine andere Remotemethode hinzuzufügen, funktioniert das nicht wie erforderlich, möglicherweise aufgrund eines Syntaxfehlers.

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

ich auch einige Varianten ausprobiert, wie die remoteMethods Deklaration in einem Array usw. fusionieren, aber keiner funktionieren würde. Bitte schlagen Sie vor, wo ich nicht richtig bin.

Antwort

1

Sie müssen den Pfad für sie angeben.

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}, 
     http: { 
       path: "/signup", 
       verb: 'post', 
       status: 201 
      } 
     } 
    ); 

    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}, 
     http: { 
       path: "/reset-password", 
       verb: 'post', 
       status: 201 
      } 
     } 
    );