]>
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/check' | |
5 | import { isDateValid } from '../../helpers/custom-validators/misc' | |
6 | ||
7 | const videosSearchValidator = [ | |
8 | query('search').optional().not().isEmpty().withMessage('Should have a valid search'), | |
9 | ||
10 | query('startDate').optional().custom(isDateValid).withMessage('Should have a valid start date'), | |
11 | query('endDate').optional().custom(isDateValid).withMessage('Should have a valid end date'), | |
12 | ||
13 | query('durationMin').optional().isInt().withMessage('Should have a valid min duration'), | |
14 | query('durationMax').optional().isInt().withMessage('Should have a valid max duration'), | |
15 | ||
16 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
17 | logger.debug('Checking videos search query', { parameters: req.query }) | |
18 | ||
19 | if (areValidationErrors(req, res)) return | |
20 | ||
21 | return next() | |
22 | } | |
23 | ] | |
24 | ||
25 | const videoChannelsSearchValidator = [ | |
26 | query('search').not().isEmpty().withMessage('Should have a valid search'), | |
27 | ||
28 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
29 | logger.debug('Checking video channels search query', { parameters: req.query }) | |
30 | ||
31 | if (areValidationErrors(req, res)) return | |
32 | ||
33 | return next() | |
34 | } | |
35 | ] | |
36 | ||
37 | // --------------------------------------------------------------------------- | |
38 | ||
39 | export { | |
40 | videoChannelsSearchValidator, | |
41 | videosSearchValidator | |
42 | } |