我有两个问题关于" beforeRemote"环回的方法 -
我的代码 -
Installation.beforeRemote("create", function (context, result, next) {
var data = context.req.body;
console.log("ImEI" + data.imei);
data.vendor = "jahid";
var self = this;
var filter = {where: {imei: data.imei}};
//the self here point to global object. but i want self to point to model
self.findOne(filter, function (err, result) {
if (result) {
data.id = result.id;
self.upsert(data, function(err, result){
if(err){
next(err);
} else if(result) {
//here i want to send a valid response back to client with 200 and body as my model.
next(data);
}
});
return;
}
next();
});
});
答案 0 :(得分:1)
您可以从module.exports声明访问安装模型:
module.exports = function(Installation) {
...
Installation.upsert...
...
}
您可以从context
对象访问响应对象。因此,您只需回复context.res.send('hello world')
之类的内容,而不是致电next()
。