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 });