updated comments to return in desc order by date

This commit is contained in:
ak 2023-09-28 14:18:24 -07:00
parent ce76438f2e
commit ad5123f10a
2 changed files with 8 additions and 4 deletions

View file

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

View file

@ -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,