search.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import * as express from 'express'
  2. import { areValidationErrors } from './utils'
  3. import { logger } from '../../helpers/logger'
  4. import { query } from 'express-validator/check'
  5. import { isDateValid } from '../../helpers/custom-validators/misc'
  6. const videosSearchValidator = [
  7. query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
  8. query('startDate').optional().custom(isDateValid).withMessage('Should have a valid start date'),
  9. query('endDate').optional().custom(isDateValid).withMessage('Should have a valid end date'),
  10. query('originallyPublishedStartDate').optional().custom(isDateValid).withMessage('Should have a valid published start date'),
  11. query('originallyPublishedEndDate').optional().custom(isDateValid).withMessage('Should have a valid published end date'),
  12. query('durationMin').optional().isInt().withMessage('Should have a valid min duration'),
  13. query('durationMax').optional().isInt().withMessage('Should have a valid max duration'),
  14. (req: express.Request, res: express.Response, next: express.NextFunction) => {
  15. logger.debug('Checking videos search query', { parameters: req.query })
  16. if (areValidationErrors(req, res)) return
  17. return next()
  18. }
  19. ]
  20. const videoChannelsSearchValidator = [
  21. query('search').not().isEmpty().withMessage('Should have a valid search'),
  22. (req: express.Request, res: express.Response, next: express.NextFunction) => {
  23. logger.debug('Checking video channels search query', { parameters: req.query })
  24. if (areValidationErrors(req, res)) return
  25. return next()
  26. }
  27. ]
  28. // ---------------------------------------------------------------------------
  29. export {
  30. videoChannelsSearchValidator,
  31. videosSearchValidator
  32. }