Necessity checking if video exists or not

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"))
})


here I am making a add comment to video controller
i am fetching the video id (mongoDB id) from url param and user id from req.user (a custom middleware is responsible to check if user is logged in or not and if so adds the user to req object)
then if video id is valid mongo id and comment content exists I am creating a new comment doc.
Now my question is i am not checking if a video with that ID already exists or not, so Should I do a query for that or do i not have to since user will have to click a video in order to be able to comment on it
Was this page helpful?