let userBuilds = [];
Wishlist.find({}, function (err, builds) {
if (err)
{
console.log("Cannot fetch wishlisted builds");
return res.redirect('back');
}
async.forEachOf(builds, function (build, key, callback) {
Builds.find({ name: build.name }, function (err, detailBuild) {
if (err)
{
console.log("Cannot fetch detail from wishlisted builds");
return res.redirect('back');
}
userBuilds.push(detailBuild[0]);
callback();
});
}, function (err) {
if (err)
{
console.log("Error in rendering page");
return res.redirect('back');
}
return res.render('wishlist', {
title: "Wishlist",
email: req.session.email ? req.session.email : undefined,
builds: userBuilds,
layout: false
});
});
});