updated comments to return in desc order by date
This commit is contained in:
parent
ce76438f2e
commit
ad5123f10a
2 changed files with 8 additions and 4 deletions
|
|
@ -47,9 +47,7 @@ exports.post = [
|
||||||
|
|
||||||
// returns comment in json format - R
|
// returns comment in json format - R
|
||||||
exports.get = asyncHandler(async (req, res, next) => {
|
exports.get = asyncHandler(async (req, res, next) => {
|
||||||
const comment = await Comment.findOne({ _id: req.params.commentID })
|
const comment = await Comment.findOneById(req.params.commentID).lean().exec();
|
||||||
.lean()
|
|
||||||
.exec();
|
|
||||||
return res.status(200).json({ comment });
|
return res.status(200).json({ comment });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,13 @@ 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 dbPost = 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 comments = await Comment.find({ post: dbPost._id })
|
||||||
|
.sort({
|
||||||
|
field: "date",
|
||||||
|
desc,
|
||||||
|
})
|
||||||
|
.lean()
|
||||||
|
.exec();
|
||||||
const post = {
|
const post = {
|
||||||
title: dbPost.title,
|
title: dbPost.title,
|
||||||
date: dbPost.date,
|
date: dbPost.date,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue