1 import express from 'express'
2 import { VideoCommentModel } from '@server/models/video/video-comment'
3 import { MVideoId } from '@server/types/models'
4 import { forceNumber } from '@shared/core-utils'
5 import { HttpStatusCode, ServerErrorCode } from '@shared/models'
7 async function doesVideoCommentThreadExist (idArg: number | string, video: MVideoId, res: express.Response) {
8 const id = forceNumber(idArg)
9 const videoComment = await VideoCommentModel.loadById(id)
13 status: HttpStatusCode.NOT_FOUND_404,
14 message: 'Video comment thread not found'
19 if (videoComment.videoId !== video.id) {
21 type: ServerErrorCode.COMMENT_NOT_ASSOCIATED_TO_VIDEO,
22 message: 'Video comment is not associated to this video.'
27 if (videoComment.inReplyToCommentId !== null) {
28 res.fail({ message: 'Video comment is not a thread.' })
32 res.locals.videoCommentThread = videoComment
36 async function doesVideoCommentExist (idArg: number | string, video: MVideoId, res: express.Response) {
37 const id = forceNumber(idArg)
38 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
42 status: HttpStatusCode.NOT_FOUND_404,
43 message: 'Video comment thread not found'
48 if (videoComment.videoId !== video.id) {
50 type: ServerErrorCode.COMMENT_NOT_ASSOCIATED_TO_VIDEO,
51 message: 'Video comment is not associated to this video.'
56 res.locals.videoCommentFull = videoComment
60 async function doesCommentIdExist (idArg: number | string, res: express.Response) {
61 const id = forceNumber(idArg)
62 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
66 status: HttpStatusCode.NOT_FOUND_404,
67 message: 'Video comment thread not found'
72 res.locals.videoCommentFull = videoComment
77 doesVideoCommentThreadExist,
78 doesVideoCommentExist,