added comments to post when post requested

This commit is contained in:
ak 2023-09-28 03:44:44 -07:00
parent 23314af0d0
commit ce76438f2e

View file

@ -94,9 +94,18 @@ exports.post = [
// returns post in json format - R // returns post in json format - R
exports.get = asyncHandler(async (req, res, next) => { 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 is not published, not publicly visible
if (!post.published) { if (!dbPost.published) {
hasToken(); hasToken();
sameAuthor(); sameAuthor();
return res.status(200).json({ post }); return res.status(200).json({ post });