]>
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').optional().custom(isDateValid).withMessage('Should have a valid start date'), | |
12 | query('endDate').optional().custom(isDateValid).withMessage('Should have a valid end date'), | |
13 | ||
14 | query('originallyPublishedStartDate').optional().custom(isDateValid).withMessage('Should have a valid published start date'), | |
15 | query('originallyPublishedEndDate').optional().custom(isDateValid).withMessage('Should have a valid published end date'), | |
16 | ||
17 | query('durationMin').optional().isInt().withMessage('Should have a valid min duration'), | |
18 | query('durationMax').optional().isInt().withMessage('Should have a valid max duration'), | |
19 | ||
20 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), | |
21 | ||
22 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
23 | logger.debug('Checking videos search query', { parameters: req.query }) | |
24 | ||
25 | if (areValidationErrors(req, res)) return | |
26 | ||
27 | return next() | |
28 | } | |
29 | ] | |
30 | ||
31 | const videoChannelsListSearchValidator = [ | |
32 | query('search').not().isEmpty().withMessage('Should have a valid search'), | |
33 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), | |
34 | ||
35 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
36 | logger.debug('Checking video channels search query', { parameters: req.query }) | |
37 | ||
38 | if (areValidationErrors(req, res)) return | |
39 | ||
40 | return next() | |
41 | } | |
42 | ] | |
43 | ||
44 | const videoChannelsOwnSearchValidator = [ | |
45 | query('search').optional().not().isEmpty().withMessage('Should have a valid search'), | |
46 | ||
47 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
48 | logger.debug('Checking video channels search query', { parameters: req.query }) | |
49 | ||
50 | if (areValidationErrors(req, res)) return | |
51 | ||
52 | return next() | |
53 | } | |
54 | ] | |
55 | ||
56 | // --------------------------------------------------------------------------- | |
57 | ||
58 | export { | |
59 | videosSearchValidator, | |
60 | videoChannelsListSearchValidator, | |
61 | videoChannelsOwnSearchValidator | |
62 | } |