aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/search.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/search.ts')
-rw-r--r--server/middlewares/validators/search.ts31
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { areValidationErrors } from './utils'
3import { logger } from '../../helpers/logger'
4import { query } from 'express-validator' 2import { query } from 'express-validator'
5import { isDateValid } from '../../helpers/custom-validators/misc'
6import { isSearchTargetValid } from '@server/helpers/custom-validators/search' 3import { isSearchTargetValid } from '@server/helpers/custom-validators/search'
4import { isDateValid } from '../../helpers/custom-validators/misc'
5import { logger } from '../../helpers/logger'
6import { areValidationErrors } from './shared'
7 7
8const videosSearchValidator = [ 8const 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
44const videoChannelsOwnSearchValidator = [ 52const 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 = [
58export { 67export {
59 videosSearchValidator, 68 videosSearchValidator,
60 videoChannelsListSearchValidator, 69 videoChannelsListSearchValidator,
61 videoChannelsOwnSearchValidator 70 videoPlaylistsListSearchValidator
62} 71}