diff options
Diffstat (limited to 'server/middlewares/validators/search.ts')
-rw-r--r-- | server/middlewares/validators/search.ts | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/server/middlewares/validators/search.ts b/server/middlewares/validators/search.ts index 78213c70d..7bbf81048 100644 --- a/server/middlewares/validators/search.ts +++ b/server/middlewares/validators/search.ts | |||
@@ -1,18 +1,26 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { areValidationErrors } from './utils' | ||
3 | import { logger } from '../../helpers/logger' | ||
4 | import { query } from 'express-validator' | 2 | import { query } from 'express-validator' |
5 | import { isDateValid } from '../../helpers/custom-validators/misc' | ||
6 | import { isSearchTargetValid } from '@server/helpers/custom-validators/search' | 3 | import { isSearchTargetValid } from '@server/helpers/custom-validators/search' |
4 | import { isDateValid } from '../../helpers/custom-validators/misc' | ||
5 | import { logger } from '../../helpers/logger' | ||
6 | import { areValidationErrors } from './shared' | ||
7 | 7 | ||
8 | const videosSearchValidator = [ | 8 | const videosSearchValidator = [ |
9 | query('search').optional().not().isEmpty().withMessage('Should have a valid search'), | 9 | query('search').optional().not().isEmpty().withMessage('Should have a valid search'), |
10 | 10 | ||
11 | query('startDate').optional().custom(isDateValid).withMessage('Should have a valid start date'), | 11 | query('startDate') |
12 | query('endDate').optional().custom(isDateValid).withMessage('Should have a valid end date'), | 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'), | ||
13 | 17 | ||
14 | query('originallyPublishedStartDate').optional().custom(isDateValid).withMessage('Should have a valid published start date'), | 18 | query('originallyPublishedStartDate') |
15 | query('originallyPublishedEndDate').optional().custom(isDateValid).withMessage('Should have a valid published end date'), | 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'), | ||
16 | 24 | ||
17 | query('durationMin').optional().isInt().withMessage('Should have a valid min duration'), | 25 | query('durationMin').optional().isInt().withMessage('Should have a valid min duration'), |
18 | query('durationMax').optional().isInt().withMessage('Should have a valid max duration'), | 26 | query('durationMax').optional().isInt().withMessage('Should have a valid max duration'), |
@@ -41,11 +49,12 @@ const videoChannelsListSearchValidator = [ | |||
41 | } | 49 | } |
42 | ] | 50 | ] |
43 | 51 | ||
44 | const videoChannelsOwnSearchValidator = [ | 52 | const videoPlaylistsListSearchValidator = [ |
45 | query('search').optional().not().isEmpty().withMessage('Should have a valid search'), | 53 | query('search').not().isEmpty().withMessage('Should have a valid search'), |
54 | query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), | ||
46 | 55 | ||
47 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 56 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
48 | logger.debug('Checking video channels search query', { parameters: req.query }) | 57 | logger.debug('Checking video playlists search query', { parameters: req.query }) |
49 | 58 | ||
50 | if (areValidationErrors(req, res)) return | 59 | if (areValidationErrors(req, res)) return |
51 | 60 | ||
@@ -58,5 +67,5 @@ const videoChannelsOwnSearchValidator = [ | |||
58 | export { | 67 | export { |
59 | videosSearchValidator, | 68 | videosSearchValidator, |
60 | videoChannelsListSearchValidator, | 69 | videoChannelsListSearchValidator, |
61 | videoChannelsOwnSearchValidator | 70 | videoPlaylistsListSearchValidator |
62 | } | 71 | } |