From ce76438f2e81991af8452e9fb267b4a69b2aef5b Mon Sep 17 00:00:00 2001 From: ak Date: Thu, 28 Sep 2023 03:44:44 -0700 Subject: [PATCH] added comments to post when post requested --- controllers/post.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/controllers/post.js b/controllers/post.js index 7165862..d9ba4f0 100644 --- a/controllers/post.js +++ b/controllers/post.js @@ -94,9 +94,18 @@ exports.post = [ // returns post in json format - R exports.get = asyncHandler(async (req, res, next) => { - const post = await Post.findById(req.params.postID).lean().exec(); + const dbPost = await Post.findById(req.params.postID).lean().exec(); + const comments = await Comment.find({ post: dbPost._id }); + const post = { + title: dbPost.title, + date: dbPost.date, + text: dbPost.text, + author: dbPost.author, + _id: dbPost._id, + comments: comments, + }; // if post is not published, not publicly visible - if (!post.published) { + if (!dbPost.published) { hasToken(); sameAuthor(); return res.status(200).json({ post });