1 import express from 'express'
2 import { VideoCommentModel } from '@server/models/video/video-comment'
3 import { MVideoId } from '@server/types/models'
4 import { HttpStatusCode, ServerErrorCode } 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) {
20 type: ServerErrorCode.COMMENT_NOT_ASSOCIATED_TO_VIDEO,
21 message: 'Video comment is not associated to this video.'
26 if (videoComment.inReplyToCommentId !== null) {
27 res.fail({ message: 'Video comment is not a thread.' })
31 res.locals.videoCommentThread = videoComment
35 async function doesVideoCommentExist (idArg: number | string, video: MVideoId, res: express.Response) {
36 const id = parseInt(idArg + '', 10)
37 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
41 status: HttpStatusCode.NOT_FOUND_404,
42 message: 'Video comment thread not found'
47 if (videoComment.videoId !== video.id) {
49 type: ServerErrorCode.COMMENT_NOT_ASSOCIATED_TO_VIDEO,
50 message: 'Video comment is not associated to this video.'
55 res.locals.videoCommentFull = videoComment
59 async function doesCommentIdExist (idArg: number | string, res: express.Response) {
60 const id = parseInt(idArg + '', 10)
61 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
65 status: HttpStatusCode.NOT_FOUND_404,
66 message: 'Video comment thread not found'
71 res.locals.videoCommentFull = videoComment
76 doesVideoCommentThreadExist,
77 doesVideoCommentExist,