]>
Commit | Line | Data |
---|---|---|
1 | import * as express from 'express' | |
2 | import { areValidationErrors } from './utils' | |
3 | import { logger } from '../../helpers/logger' | |
4 | import { query } from 'express-validator' | |
5 | import { isDateValid } from '../../helpers/custom-validators/misc' | |
6 | import { isSearchTargetValid } from '@server/helpers/custom-validators/search' | |
7 | ||
8 | const videosSearchValidator = [ | |
9 | query('search').optional().not().isEmpty().withMessage('Should have a valid search'), | |
10 | ||
11 | query('startDate') | |
12 | .optional() | |
13 | .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'), | |
14 | query('endDate') | |
15 | .optional() | |
16 | .custom(isDateValid).withMessage('Should have a end date that conforms to ISO 8601'), | |
17 | ||
18 | query('originallyPublishedStartDate') | |
19 | .optional() | |
20 | .custom(isDateValid).withMessage('Should have a published start date that conforms to ISO 8601'), | |
21 | query('originallyPublishedEndDate') | |
22 | .optional() | |
23 | .custom(isDateValid).withMessage('Should have a published end date that conforms to ISO 8601'), | |
24 | ||
25 | query('durationMin').optional().isInt().withMessage('Should have a valid min duration'), | |
26 | query('durationMax').optional().isInt().withMessage('Should have a valid max duration'), | |
27 | ||
28 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), | |
29 | ||
30 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
31 | logger.debug('Checking videos search query', { parameters: req.query }) | |
32 | ||
33 | if (areValidationErrors(req, res)) return | |
34 | ||
35 | return next() | |
36 | } | |
37 | ] | |
38 | ||
39 | const videoChannelsListSearchValidator = [ | |
40 | query('search').not().isEmpty().withMessage('Should have a valid search'), | |
41 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), | |
42 | ||
43 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
44 | logger.debug('Checking video channels search query', { parameters: req.query }) | |
45 | ||
46 | if (areValidationErrors(req, res)) return | |
47 | ||
48 | return next() | |
49 | } | |
50 | ] | |
51 | ||
52 | const videoChannelsOwnSearchValidator = [ | |
53 | query('search').optional().not().isEmpty().withMessage('Should have a valid search'), | |
54 | ||
55 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
56 | logger.debug('Checking video channels search query', { parameters: req.query }) | |
57 | ||
58 | if (areValidationErrors(req, res)) return | |
59 | ||
60 | return next() | |
61 | } | |
62 | ] | |
63 | ||
64 | // --------------------------------------------------------------------------- | |
65 | ||
66 | export { | |
67 | videosSearchValidator, | |
68 | videoChannelsListSearchValidator, | |
69 | videoChannelsOwnSearchValidator | |
70 | } |