The tutorial that I am follwin has the following 2 router methods for
getting the articles from db.
router.param('article', function(req, res, next, slug) {
Article.findOne({ slug: slug})
.populate('author')
.then(function (article) {
if (!article) { return res.sendStatus(404); }
req.article = article;
return next();
}).catch(next);
});
router.get('/:article', auth.optional, function(req, res, next) {
Promise.all([
req.payload ? User.findById(req.payload.id) : null,
req.article.populate('author').execPopulate()
]).then(function(results){
var user = results[0];
return res.json({article: req.article.toJSONFor(user)});
}).catch(next);
});
I have two questions regarding the methods above,
1. How does `Promise.all()` work ?
2. Why do we need to repopulate author field in `router.get()` method when
already did that in the `router.param()` method?
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/0234f0f4-0eb1-4201-8899-10d6bd163a2e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.