2024-03-06 19:43:09 +00:00

29 lines
716 B
JavaScript
Executable File

import { Post } from "@db_models"
import fullfillPostsData from "@utils/fullfillPostsData"
export default {
method: "GET",
route: "/post/:post_id/replies",
middlewares: ["withOptionalAuthentication"],
fn: async (req, res) => {
const {
limit = 50,
offset = 0,
} = req.query
let replies = await Post.find({
reply_to: req.params.post_id,
})
.skip(offset)
.limit(limit)
.sort({ created_at: -1 })
replies = await fullfillPostsData({
posts: replies,
for_user_id: req.user?._id.toString(),
skip: offset,
})
return res.json(replies)
}
}