I am new to javascript async programming and i have a basic issue where I have a Set of code where i am doing two separate DB calls on basis of request body params . These are two methods which does a DB Call and returns a Promise
- validateExam
- validateUserExists
I want to store resullts from async call to this variable and then return it in response .
getExam: function(req, res) {
var myExam = {};
var coupon = req.body.coupon;
var email = req.body.email;
async.series([
function(callback) {
validateExam(coupon)
.then(function(success) {
assign(success);
callback(null, success);
});
},
function(callback) {
validateUserExists(email)
.then(function(result) {
callback(null, result);
})
}
], function(error, results) {
myExam.res = results;
});
res.json({
"status": 400,
"message": myExam
});
},
via Sanjay-Dev
No comments:
Post a Comment