2024-03-05 10:20:36 +00:00

29 lines
757 B
JavaScript
Executable File

import { Schematized } from "@lib"
import newComment from "../services/newComment"
export default {
method: "POST",
route: "/post/:post_id",
middlewares: ["withAuthentication"],
fn: Schematized({
required: ["message"],
select: ["message"],
}, async (req, res) => {
const { post_id } = req.params
const { message } = req.selection
try {
const comment = await newComment({
user_id: req.user._id.toString(),
parent_id: post_id,
message: message,
})
return res.json(comment)
} catch (error) {
return res.status(400).json({
error: error.message,
})
}
})
}