export const addComment = asyncHandler(async (req, res) => {
const { videoId } = req.params;
if (!isValidObjectId(videoId)) {
throw new ApiError(400, "Invalid video id");
}
const { content } = req.body;
if (!content) {
throw new ApiError(400, "Content is required");
}
const comment = await Comment.create({
content,
owner: req.user?._id,
video: videoId
})
if (!comment) {
throw new ApiError(500, "Comment creation failure");
}
return res.status(200).json(new ApiResponse(200, comment, "Comment created"))
})
export const addComment = asyncHandler(async (req, res) => {
const { videoId } = req.params;
if (!isValidObjectId(videoId)) {
throw new ApiError(400, "Invalid video id");
}
const { content } = req.body;
if (!content) {
throw new ApiError(400, "Content is required");
}
const comment = await Comment.create({
content,
owner: req.user?._id,
video: videoId
})
if (!comment) {
throw new ApiError(500, "Comment creation failure");
}
return res.status(200).json(new ApiResponse(200, comment, "Comment created"))
})