user-history.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import * as express from 'express'
  2. import { body, query } from 'express-validator'
  3. import { logger } from '../../helpers/logger'
  4. import { areValidationErrors } from './utils'
  5. import { exists, isDateValid } from '../../helpers/custom-validators/misc'
  6. const userHistoryListValidator = [
  7. query('search')
  8. .optional()
  9. .custom(exists).withMessage('Should have a valid search'),
  10. (req: express.Request, res: express.Response, next: express.NextFunction) => {
  11. logger.debug('Checking userHistoryListValidator parameters', { parameters: req.query })
  12. if (areValidationErrors(req, res)) return
  13. return next()
  14. }
  15. ]
  16. const userHistoryRemoveValidator = [
  17. body('beforeDate')
  18. .optional()
  19. .custom(isDateValid).withMessage('Should have a valid before date'),
  20. (req: express.Request, res: express.Response, next: express.NextFunction) => {
  21. logger.debug('Checking userHistoryRemoveValidator parameters', { parameters: req.body })
  22. if (areValidationErrors(req, res)) return
  23. return next()
  24. }
  25. ]
  26. // ---------------------------------------------------------------------------
  27. export {
  28. userHistoryListValidator,
  29. userHistoryRemoveValidator
  30. }