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'
8 const videosSearchValidator = [
9 query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
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'),
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'),
17 query('durationMin').optional().isInt().withMessage('Should have a valid min duration'),
18 query('durationMax').optional().isInt().withMessage('Should have a valid max duration'),
20 query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'),
22 (req: express.Request, res: express.Response, next: express.NextFunction) => {
23 logger.debug('Checking videos search query', { parameters: req.query })
25 if (areValidationErrors(req, res)) return
31 const videoChannelsSearchValidator = [
32 query('search').not().isEmpty().withMessage('Should have a valid search'),
33 query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'),
35 (req: express.Request, res: express.Response, next: express.NextFunction) => {
36 logger.debug('Checking video channels search query', { parameters: req.query })
38 if (areValidationErrors(req, res)) return
44 // ---------------------------------------------------------------------------
47 videoChannelsSearchValidator,