diff --git a/controllers/comment.js b/controllers/comment.js index 385501d..3b41af0 100644 --- a/controllers/comment.js +++ b/controllers/comment.js @@ -47,9 +47,7 @@ exports.post = [ // returns comment in json format - R exports.get = asyncHandler(async (req, res, next) => { - const comment = await Comment.findOne({ _id: req.params.commentID }) - .lean() - .exec(); + const comment = await Comment.findOneById(req.params.commentID).lean().exec(); return res.status(200).json({ comment }); }); diff --git a/controllers/post.js b/controllers/post.js index d9ba4f0..840c55e 100644 --- a/controllers/post.js +++ b/controllers/post.js @@ -95,7 +95,13 @@ exports.post = [ // returns post in json format - R exports.get = asyncHandler(async (req, res, next) => { const dbPost = await Post.findById(req.params.postID).lean().exec(); - const comments = await Comment.find({ post: dbPost._id }); + const comments = await Comment.find({ post: dbPost._id }) + .sort({ + field: "date", + desc, + }) + .lean() + .exec(); const post = { title: dbPost.title, date: dbPost.date,