INNER CODE UNIT · JavaScript
updateComment
ihtasham42/social-media-app · controllers/commentControllers.js:99
const updateComment = async (req, res) => {
try {
const commentId = req.params.id;
const { userId, content, isAdmin } = req.body;
if (!content) {
throw new Error("All input required");
}
const comment = await Comment.findById(commentId);
if (!comment) {
throw new Error("Comment not found");
}
if (comment.commenter != userId && !isAdmin) {
throw new Error("Not authorized to update comment");
}