2
1

logs.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import express from 'express'
  2. import { query } from 'express-validator'
  3. import { isStringArray } from '@server/helpers/custom-validators/search'
  4. import { isValidLogLevel } from '../../helpers/custom-validators/logs'
  5. import { isDateValid, toArray } from '../../helpers/custom-validators/misc'
  6. import { logger } from '../../helpers/logger'
  7. import { areValidationErrors } from './shared'
  8. const getLogsValidator = [
  9. query('startDate')
  10. .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
  11. query('level')
  12. .optional()
  13. .custom(isValidLogLevel).withMessage('Should have a valid level'),
  14. query('tagsOneOf')
  15. .optional()
  16. .customSanitizer(toArray)
  17. .custom(isStringArray).withMessage('Should have a valid one of tags array'),
  18. query('endDate')
  19. .optional()
  20. .custom(isDateValid).withMessage('Should have an end date that conforms to ISO 8601'),
  21. (req: express.Request, res: express.Response, next: express.NextFunction) => {
  22. logger.debug('Checking getLogsValidator parameters.', { parameters: req.query })
  23. if (areValidationErrors(req, res)) return
  24. return next()
  25. }
  26. ]
  27. const getAuditLogsValidator = [
  28. query('startDate')
  29. .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
  30. query('endDate')
  31. .optional()
  32. .custom(isDateValid).withMessage('Should have a end date that conforms to ISO 8601'),
  33. (req: express.Request, res: express.Response, next: express.NextFunction) => {
  34. logger.debug('Checking getAuditLogsValidator parameters.', { parameters: req.query })
  35. if (areValidationErrors(req, res)) return
  36. return next()
  37. }
  38. ]
  39. // ---------------------------------------------------------------------------
  40. export {
  41. getLogsValidator,
  42. getAuditLogsValidator
  43. }