search.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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'
  7. const videosSearchValidator = [
  8. query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
  9. query('startDate').optional().custom(isDateValid).withMessage('Should have a valid start date'),
  10. query('endDate').optional().custom(isDateValid).withMessage('Should have a valid end date'),
  11. query('originallyPublishedStartDate').optional().custom(isDateValid).withMessage('Should have a valid published start date'),
  12. query('originallyPublishedEndDate').optional().custom(isDateValid).withMessage('Should have a valid published end date'),
  13. query('durationMin').optional().isInt().withMessage('Should have a valid min duration'),
  14. query('durationMax').optional().isInt().withMessage('Should have a valid max duration'),
  15. query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'),
  16. (req: express.Request, res: express.Response, next: express.NextFunction) => {
  17. logger.debug('Checking videos search query', { parameters: req.query })
  18. if (areValidationErrors(req, res)) return
  19. return next()
  20. }
  21. ]
  22. const videoChannelsListSearchValidator = [
  23. query('search').not().isEmpty().withMessage('Should have a valid search'),
  24. query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'),
  25. (req: express.Request, res: express.Response, next: express.NextFunction) => {
  26. logger.debug('Checking video channels search query', { parameters: req.query })
  27. if (areValidationErrors(req, res)) return
  28. return next()
  29. }
  30. ]
  31. const videoChannelsOwnSearchValidator = [
  32. query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
  33. (req: express.Request, res: express.Response, next: express.NextFunction) => {
  34. logger.debug('Checking video channels search query', { parameters: req.query })
  35. if (areValidationErrors(req, res)) return
  36. return next()
  37. }
  38. ]
  39. // ---------------------------------------------------------------------------
  40. export {
  41. videosSearchValidator,
  42. videoChannelsListSearchValidator,
  43. videoChannelsOwnSearchValidator
  44. }