added comments to post when post requested
This commit is contained in:
parent
23314af0d0
commit
ce76438f2e
1 changed files with 11 additions and 2 deletions
|
|
@ -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 });
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue