Skip to content

Instantly share code, notes, and snippets.

@jcunanan05
Last active May 31, 2019 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcunanan05/012350de552495f424dee6ad4dd9c607 to your computer and use it in GitHub Desktop.
Save jcunanan05/012350de552495f424dee6ad4dd9c607 to your computer and use it in GitHub Desktop.
// Display detail page for a specific Author.
exports.author_detail = async function(req, res) {
// async.parallel(
// {
// author: function(callback) {
// Author.findById(req.params.id).exec(callback);
// },
// author_books: function(callback) {
// Book.find({ author: req.params.id }, "title summary").exec(callback);
// }
// },
// function(err, results) {
// res.render("author_detail", {
// title: "Author Detail",
// author: results.author,
// author_books: results.author_books
// });
// }
// );
// try {
// const author = await Author.findById(req.params.id);
// const author_books = await Book.find(
// { author: req.params.id },
// "title summary"
// );
// res.render("author_detail", {
// title: "Author Detail",
// author,
// author_books
// });
// } catch (error) {
// return next(error);
// }
Promise.all([
await Author.findById(req.params.id),
await Book.find({ author: req.params.id }, "title summary")
])
.then(([author, author_books]) => {
res.render("author_detail", {
author,
author_books
});
})
.catch(err => next(err));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment