logs.ts 993 B

12345678910111213141516171819202122232425262728293031
  1. import * as express from 'express'
  2. import { logger } from '../../helpers/logger'
  3. import { areValidationErrors } from './utils'
  4. import { isDateValid } from '../../helpers/custom-validators/misc'
  5. import { query } from 'express-validator/check'
  6. import { isValidLogLevel } from '../../helpers/custom-validators/logs'
  7. const getLogsValidator = [
  8. query('startDate')
  9. .custom(isDateValid).withMessage('Should have a valid start date'),
  10. query('level')
  11. .optional()
  12. .custom(isValidLogLevel).withMessage('Should have a valid level'),
  13. query('endDate')
  14. .optional()
  15. .custom(isDateValid).withMessage('Should have a valid end date'),
  16. (req: express.Request, res: express.Response, next: express.NextFunction) => {
  17. logger.debug('Checking getLogsValidator parameters.', { parameters: req.query })
  18. if (areValidationErrors(req, res)) return
  19. return next()
  20. }
  21. ]
  22. // ---------------------------------------------------------------------------
  23. export {
  24. getLogsValidator
  25. }