Disclaimer: new to JS and everything around it. :)
I was wondering if we could nest async functions within one another
I have a waterfall method in node:
/**
* POST new travel wish
*/
router.post('/add', function(req, res) {
var db = req.db;
console.log(req.body);
// add properties: customer_id and timestamp
var date = new Date();
//...
var notif;
async.waterfall(
[
// find the User
function(next){
db.collection(userCollection).findOne({_id: new ObjectId(req.session.userID)}, next);
},
// insert a new travelwish
function(user, next){
notif = {
'username': user.username,
};
// TODO: add a async.parallel
db.collection('travelwishlist').insert(req.body, next);
},
// setup timer for processing and send confirmation
function(insertedTravelWish, next){
NotificationManager.sendConfirmationNotification(notif);
next(null, insertedTravelWish);
}
],
// waterfall callback --> send http response.
function (err, insertedTravelWish) {
res.send(
//if everything is ok the system sends the travel wish ID to the client otherwise error
(err === null) ? { msg: insertedTravelWish[0]["_id"] } : { msg: 'err' }
);
}
);
});
I want to insert multiple items instead of just one.
I think i can do this with parallel, but can I put it inside the existing waterfall?