]>
Commit | Line | Data |
---|---|---|
57c36b27 | 1 | import * as express from 'express' |
c8861d5d | 2 | import { query } from 'express-validator' |
3b0bd70a | 3 | import { isSearchTargetValid } from '@server/helpers/custom-validators/search' |
10363c74 C |
4 | import { isDateValid } from '../../helpers/custom-validators/misc' |
5 | import { logger } from '../../helpers/logger' | |
6 | import { areValidationErrors } from './shared' | |
57c36b27 | 7 | |
f37dc0dd | 8 | const videosSearchValidator = [ |
d4112450 | 9 | query('search').optional().not().isEmpty().withMessage('Should have a valid search'), |
57c36b27 | 10 | |
70330f63 RK |
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'), | |
c74c9be9 | 24 | |
d525fc39 C |
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 | ||
3b0bd70a C |
28 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), |
29 | ||
d525fc39 | 30 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
f37dc0dd C |
31 | logger.debug('Checking videos search query', { parameters: req.query }) |
32 | ||
33 | if (areValidationErrors(req, res)) return | |
34 | ||
35 | return next() | |
36 | } | |
37 | ] | |
38 | ||
7b390964 | 39 | const videoChannelsListSearchValidator = [ |
f37dc0dd | 40 | query('search').not().isEmpty().withMessage('Should have a valid search'), |
3b0bd70a | 41 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), |
f37dc0dd C |
42 | |
43 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
44 | logger.debug('Checking video channels search query', { parameters: req.query }) | |
d525fc39 C |
45 | |
46 | if (areValidationErrors(req, res)) return | |
47 | ||
48 | return next() | |
49 | } | |
50 | ] | |
51 | ||
37a44fc9 C |
52 | const videoPlaylistsListSearchValidator = [ |
53 | query('search').not().isEmpty().withMessage('Should have a valid search'), | |
54 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), | |
bc99dfe5 RK |
55 | |
56 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
37a44fc9 | 57 | logger.debug('Checking video playlists search query', { parameters: req.query }) |
bc99dfe5 RK |
58 | |
59 | if (areValidationErrors(req, res)) return | |
60 | ||
61 | return next() | |
62 | } | |
63 | ] | |
64 | ||
57c36b27 C |
65 | // --------------------------------------------------------------------------- |
66 | ||
67 | export { | |
bc99dfe5 | 68 | videosSearchValidator, |
7b390964 | 69 | videoChannelsListSearchValidator, |
37a44fc9 | 70 | videoPlaylistsListSearchValidator |
57c36b27 | 71 | } |