]>
Commit | Line | Data |
---|---|---|
268eebed C |
1 | import * as express from 'express' |
2 | import 'express-validator' | |
3 | import { body, param } from 'express-validator/check' | |
6e46de09 | 4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' |
6e46de09 C |
5 | import { logger } from '../../../helpers/logger' |
6 | import { areValidationErrors } from '../utils' | |
268eebed | 7 | import { |
268eebed C |
8 | isVideoAbuseModerationCommentValid, |
9 | isVideoAbuseReasonValid, | |
10 | isVideoAbuseStateValid | |
6e46de09 | 11 | } from '../../../helpers/custom-validators/video-abuses' |
3e753302 | 12 | import { doesVideoAbuseExist, doesVideoExist } from '../../../helpers/middlewares' |
268eebed C |
13 | |
14 | const videoAbuseReportValidator = [ | |
15 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | |
16 | body('reason').custom(isVideoAbuseReasonValid).withMessage('Should have a valid reason'), | |
17 | ||
18 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
19 | logger.debug('Checking videoAbuseReport parameters', { parameters: req.body }) | |
20 | ||
21 | if (areValidationErrors(req, res)) return | |
0f6acda1 | 22 | if (!await doesVideoExist(req.params.videoId, res)) return |
268eebed C |
23 | |
24 | return next() | |
25 | } | |
26 | ] | |
27 | ||
28 | const videoAbuseGetValidator = [ | |
29 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | |
30 | param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'), | |
31 | ||
32 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
33 | logger.debug('Checking videoAbuseGetValidator parameters', { parameters: req.body }) | |
34 | ||
35 | if (areValidationErrors(req, res)) return | |
0f6acda1 C |
36 | if (!await doesVideoExist(req.params.videoId, res)) return |
37 | if (!await doesVideoAbuseExist(req.params.id, res.locals.video.id, res)) return | |
268eebed C |
38 | |
39 | return next() | |
40 | } | |
41 | ] | |
42 | ||
43 | const videoAbuseUpdateValidator = [ | |
44 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), | |
45 | param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'), | |
46 | body('state') | |
47 | .optional() | |
48 | .custom(isVideoAbuseStateValid).withMessage('Should have a valid video abuse state'), | |
49 | body('moderationComment') | |
50 | .optional() | |
51 | .custom(isVideoAbuseModerationCommentValid).withMessage('Should have a valid video moderation comment'), | |
52 | ||
53 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
54 | logger.debug('Checking videoAbuseUpdateValidator parameters', { parameters: req.body }) | |
55 | ||
56 | if (areValidationErrors(req, res)) return | |
0f6acda1 C |
57 | if (!await doesVideoExist(req.params.videoId, res)) return |
58 | if (!await doesVideoAbuseExist(req.params.id, res.locals.video.id, res)) return | |
268eebed C |
59 | |
60 | return next() | |
61 | } | |
62 | ] | |
63 | ||
64 | // --------------------------------------------------------------------------- | |
65 | ||
66 | export { | |
67 | videoAbuseReportValidator, | |
68 | videoAbuseGetValidator, | |
69 | videoAbuseUpdateValidator | |
70 | } |