delete后的loopback自定义发送给客户端的结果

时间:2016-06-22 10:21:55

标签: node.js loopbackjs

在我的环回应用程序中,我必须自定义发送给客户端的删除结果。

xxxxx.observe('before delete', function(ctx, next) {
      xxxxx.find({
          where: {
            id: ctx.where.id
          }
        }, function (err, transaction) {
            if(yyyy.length > 0){
                var id = yyyy[0]['id'];
                pgclient.query("delete from qqq where kkkk = '"+id+"' ", function(err, dbRes){
                  if(err){
                    next(err);
                  } else{
                    next();----------------> here i have to customize the result
                  }
                });
            } else {
                next({"message":" for the given id"});
            }
        });
    });

现在发送给客户的结果是:

{
  "count": 1
}

但我需要将其修改为:

{"message":"Deleted Successfully"}.

我对此尝试了很多,但没有结果。请分享您的想法。

1 个答案:

答案 0 :(得分:0)

你做不到。这是操作挂钩,next回调仅用于确定操作成功/失败。

要自定义消息,您应该在远程方法或远程挂钩

中进行