]>
Commit | Line | Data |
---|---|---|
41fb13c3 | 1 | import express from 'express' |
7177b46c C |
2 | import { body, param, query } from 'express-validator' |
3 | import { exists, isDateValid, isIdValid } from '../../helpers/custom-validators/misc' | |
10363c74 C |
4 | import { logger } from '../../helpers/logger' |
5 | import { areValidationErrors } from './shared' | |
d8b34ee5 RK |
6 | |
7 | const userHistoryListValidator = [ | |
8 | query('search') | |
9 | .optional() | |
10 | .custom(exists).withMessage('Should have a valid search'), | |
11 | ||
12 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
13 | logger.debug('Checking userHistoryListValidator parameters', { parameters: req.query }) | |
14 | ||
15 | if (areValidationErrors(req, res)) return | |
16 | ||
17 | return next() | |
18 | } | |
19 | ] | |
8b9a525a | 20 | |
7177b46c | 21 | const userHistoryRemoveAllValidator = [ |
8b9a525a C |
22 | body('beforeDate') |
23 | .optional() | |
70330f63 | 24 | .custom(isDateValid).withMessage('Should have a before date that conforms to ISO 8601'), |
8b9a525a C |
25 | |
26 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
7177b46c C |
27 | logger.debug('Checking userHistoryRemoveAllValidator parameters', { parameters: req.body }) |
28 | ||
29 | if (areValidationErrors(req, res)) return | |
30 | ||
31 | return next() | |
32 | } | |
33 | ] | |
34 | ||
35 | const userHistoryRemoveElementValidator = [ | |
36 | param('videoId') | |
37 | .custom(isIdValid).withMessage('Should have a valid video id'), | |
38 | ||
39 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
40 | logger.debug('Checking userHistoryRemoveElementValidator parameters', { parameters: req.params }) | |
8b9a525a C |
41 | |
42 | if (areValidationErrors(req, res)) return | |
43 | ||
44 | return next() | |
45 | } | |
46 | ] | |
47 | ||
48 | // --------------------------------------------------------------------------- | |
49 | ||
50 | export { | |
d8b34ee5 | 51 | userHistoryListValidator, |
7177b46c C |
52 | userHistoryRemoveElementValidator, |
53 | userHistoryRemoveAllValidator | |
8b9a525a | 54 | } |