1 import * as express from 'express'
2 import { VideoCommentModel } from '@server/models/video/video-comment'
3 import { MVideoId } from '@server/types/models'
4 import { HttpStatusCode } from '@shared/models'
6 async function doesVideoCommentThreadExist (idArg: number | string, video: MVideoId, res: express.Response) {
7 const id = parseInt(idArg + '', 10)
8 const videoComment = await VideoCommentModel.loadById(id)
12 status: HttpStatusCode.NOT_FOUND_404,
13 message: 'Video comment thread not found'
18 if (videoComment.videoId !== video.id) {
19 res.fail({ message: 'Video comment is not associated to this video.' })
23 if (videoComment.inReplyToCommentId !== null) {
24 res.fail({ message: 'Video comment is not a thread.' })
28 res.locals.videoCommentThread = videoComment
32 async function doesVideoCommentExist (idArg: number | string, video: MVideoId, res: express.Response) {
33 const id = parseInt(idArg + '', 10)
34 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
38 status: HttpStatusCode.NOT_FOUND_404,
39 message: 'Video comment thread not found'
44 if (videoComment.videoId !== video.id) {
45 res.fail({ message: 'Video comment is not associated to this video.' })
49 res.locals.videoCommentFull = videoComment
53 async function doesCommentIdExist (idArg: number | string, res: express.Response) {
54 const id = parseInt(idArg + '', 10)
55 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
59 status: HttpStatusCode.NOT_FOUND_404,
60 message: 'Video comment thread not found'
65 res.locals.videoCommentFull = videoComment
70 doesVideoCommentThreadExist,
71 doesVideoCommentExist,