loopback 添加非静态远程方法报错

loopback Add non static remote method error

我正在尝试向模型添加非静态远程方法。只需按照此处的 code 即可。不幸的是,我收到了一些错误信息。

以下是我的代码

User.prototype.lastOrder = function(callback){
  console.log('print this instance object: ', this);
  callback(null)
};

User.remoteMethod('__get__lastOrder', {
  isStatic: false,
  accepts: [],
  description: 'Get the latest order of the user',
  http: {
    path: '/lastOrder',
    verb: 'get'
}

当我调用 http://localhost:3000/v1/users/1/lastOrder 时。它给了我以下错误:

remoteMethod 的第一个参数是函数名。您定义的内容无效。您需要定义一个名为 lastOrder 的函数,然后像这样修改您的代码:

User.prototype.lastOrder = function() {

}

User.remoteMethod('lastOrder', {
  isStatic:false,
  //more stuff here
}
  User.prototype.lastOrder = function(callback){
    console.log('print this instance object: ', this);
    callback(null, "this is a test");
  };

  User.remoteMethod('lastOrder', {  // should be lastOrder not __get__lastOrder
    isStatic: false,
    accepts: [],
    description: 'Get the latest order of the user',
    http: {
      path: '/lastOrder',
      verb: 'get',
      status: 200
    },
    returns: {root: true, type: 'order'}
  });