user-history.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import express from 'express'
  2. import { body, param, query } from 'express-validator'
  3. import { exists, isDateValid, isIdValid } from '../../helpers/custom-validators/misc'
  4. import { areValidationErrors } from './shared'
  5. const userHistoryListValidator = [
  6. query('search')
  7. .optional()
  8. .custom(exists),
  9. (req: express.Request, res: express.Response, next: express.NextFunction) => {
  10. if (areValidationErrors(req, res)) return
  11. return next()
  12. }
  13. ]
  14. const userHistoryRemoveAllValidator = [
  15. body('beforeDate')
  16. .optional()
  17. .custom(isDateValid).withMessage('Should have a before date that conforms to ISO 8601'),
  18. (req: express.Request, res: express.Response, next: express.NextFunction) => {
  19. if (areValidationErrors(req, res)) return
  20. return next()
  21. }
  22. ]
  23. const userHistoryRemoveElementValidator = [
  24. param('videoId')
  25. .custom(isIdValid),
  26. (req: express.Request, res: express.Response, next: express.NextFunction) => {
  27. if (areValidationErrors(req, res)) return
  28. return next()
  29. }
  30. ]
  31. // ---------------------------------------------------------------------------
  32. export {
  33. userHistoryListValidator,
  34. userHistoryRemoveElementValidator,
  35. userHistoryRemoveAllValidator
  36. }