]>
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 | 4 | import { areValidationErrors } from './shared' |
d8b34ee5 RK |
5 | |
6 | const userHistoryListValidator = [ | |
7 | query('search') | |
8 | .optional() | |
396f6f01 | 9 | .custom(exists), |
d8b34ee5 RK |
10 | |
11 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
d8b34ee5 RK |
12 | if (areValidationErrors(req, res)) return |
13 | ||
14 | return next() | |
15 | } | |
16 | ] | |
8b9a525a | 17 | |
7177b46c | 18 | const userHistoryRemoveAllValidator = [ |
8b9a525a C |
19 | body('beforeDate') |
20 | .optional() | |
70330f63 | 21 | .custom(isDateValid).withMessage('Should have a before date that conforms to ISO 8601'), |
8b9a525a C |
22 | |
23 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
7177b46c C |
24 | if (areValidationErrors(req, res)) return |
25 | ||
26 | return next() | |
27 | } | |
28 | ] | |
29 | ||
30 | const userHistoryRemoveElementValidator = [ | |
31 | param('videoId') | |
396f6f01 | 32 | .custom(isIdValid), |
7177b46c C |
33 | |
34 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
8b9a525a C |
35 | if (areValidationErrors(req, res)) return |
36 | ||
37 | return next() | |
38 | } | |
39 | ] | |
40 | ||
41 | // --------------------------------------------------------------------------- | |
42 | ||
43 | export { | |
d8b34ee5 | 44 | userHistoryListValidator, |
7177b46c C |
45 | userHistoryRemoveElementValidator, |
46 | userHistoryRemoveAllValidator | |
8b9a525a | 47 | } |