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