aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/video-comments.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/video-comments.ts')
-rw-r--r--server/middlewares/validators/video-comments.ts22
1 files changed, 19 insertions, 3 deletions
diff --git a/server/middlewares/validators/video-comments.ts b/server/middlewares/validators/video-comments.ts
index 1d19fac58..fdd092571 100644
--- a/server/middlewares/validators/video-comments.ts
+++ b/server/middlewares/validators/video-comments.ts
@@ -1,9 +1,9 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator/check' 2import { body, param } from 'express-validator/check'
3import { logger } from '../../helpers'
4import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' 3import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc'
5import { isValidVideoCommentText } from '../../helpers/custom-validators/video-comments' 4import { isValidVideoCommentText } from '../../helpers/custom-validators/video-comments'
6import { isVideoExist } from '../../helpers/custom-validators/videos' 5import { isVideoExist } from '../../helpers/custom-validators/videos'
6import { logger } from '../../helpers/logger'
7import { VideoModel } from '../../models/video/video' 7import { VideoModel } from '../../models/video/video'
8import { VideoCommentModel } from '../../models/video/video-comment' 8import { VideoCommentModel } from '../../models/video/video-comment'
9import { areValidationErrors } from './utils' 9import { areValidationErrors } from './utils'
@@ -66,13 +66,29 @@ const addVideoCommentReplyValidator = [
66 } 66 }
67] 67]
68 68
69const videoCommentGetValidator = [
70 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
71 param('commentId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid commentId'),
72
73 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
74 logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params })
75
76 if (areValidationErrors(req, res)) return
77 if (!await isVideoExist(req.params.videoId, res)) return
78 if (!await isVideoCommentExist(req.params.commentId, res.locals.video, res)) return
79
80 return next()
81 }
82]
83
69// --------------------------------------------------------------------------- 84// ---------------------------------------------------------------------------
70 85
71export { 86export {
72 listVideoCommentThreadsValidator, 87 listVideoCommentThreadsValidator,
73 listVideoThreadCommentsValidator, 88 listVideoThreadCommentsValidator,
74 addVideoCommentThreadValidator, 89 addVideoCommentThreadValidator,
75 addVideoCommentReplyValidator 90 addVideoCommentReplyValidator,
91 videoCommentGetValidator
76} 92}
77 93
78// --------------------------------------------------------------------------- 94// ---------------------------------------------------------------------------
@@ -109,7 +125,7 @@ async function isVideoCommentThreadExist (id: number, video: VideoModel, res: ex
109} 125}
110 126
111async function isVideoCommentExist (id: number, video: VideoModel, res: express.Response) { 127async function isVideoCommentExist (id: number, video: VideoModel, res: express.Response) {
112 const videoComment = await VideoCommentModel.loadById(id) 128 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
113 129
114 if (!videoComment) { 130 if (!videoComment) {
115 res.status(404) 131 res.status(404)