]>
Commit | Line | Data |
---|---|---|
57c36b27 C |
1 | import * as express from 'express' |
2 | import { areValidationErrors } from './utils' | |
3 | import { logger } from '../../helpers/logger' | |
c8861d5d | 4 | import { query } from 'express-validator' |
1cd3facc | 5 | import { isDateValid } from '../../helpers/custom-validators/misc' |
3b0bd70a | 6 | import { isSearchTargetValid } from '@server/helpers/custom-validators/search' |
57c36b27 | 7 | |
f37dc0dd | 8 | const videosSearchValidator = [ |
d4112450 | 9 | query('search').optional().not().isEmpty().withMessage('Should have a valid search'), |
57c36b27 | 10 | |
d525fc39 C |
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 | ||
c74c9be9 C |
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 | ||
d525fc39 C |
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 | ||
3b0bd70a C |
20 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), |
21 | ||
d525fc39 | 22 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
f37dc0dd C |
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 videoChannelsSearchValidator = [ | |
32 | query('search').not().isEmpty().withMessage('Should have a valid search'), | |
3b0bd70a | 33 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), |
f37dc0dd C |
34 | |
35 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
36 | logger.debug('Checking video channels search query', { parameters: req.query }) | |
d525fc39 C |
37 | |
38 | if (areValidationErrors(req, res)) return | |
39 | ||
40 | return next() | |
41 | } | |
42 | ] | |
43 | ||
bc99dfe5 RK |
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 | ||
57c36b27 C |
56 | // --------------------------------------------------------------------------- |
57 | ||
58 | export { | |
bc99dfe5 | 59 | videosSearchValidator, |
f37dc0dd | 60 | videoChannelsSearchValidator, |
bc99dfe5 | 61 | videoChannelsOwnSearchValidator |
57c36b27 | 62 | } |