如何在/ Users / Reset调用后远程挂钩/操作挂钩?

时间:2017-01-18 01:10:23

标签: loopbackjs

我有这个,但是当我执行* POST用户/重置

时它没有击中它
User.observe('after save', function(ctx, next) {
  if (ctx.instance) {
    console.log('Saved %s#%s', ctx.Model.modelName, ctx.instance.id);
  } else {
    console.log('Updated %s matching %j',
      ctx.Model.pluralModelName,
      ctx.where);
  }
  next();
});

1 个答案:

答案 0 :(得分:0)

AFAIK在环回中没有/users/reset的预定义方法。因此必须定义一些远程方法来使用它。我不确定你真的想问什么,但我认为这将解决你的问题。

module.exports = function(User){

    User.reset = function(msg, cb) {
      console.log("Reset Post method is getting called");
      cb(null, 'Greetings... ' - msg);
    }

    User.remoteMethod('reset', {
          accepts: {arg: 'msg', type: 'string'},
          returns: {arg: 'greeting', type: 'string'}
    });
};