aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/logs.ts
blob: 7380c6edde6a174fb7fdf1656e8b86a686f25d9a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import * as express from 'express'
import { logger } from '../../helpers/logger'
import { areValidationErrors } from './utils'
import { isDateValid } from '../../helpers/custom-validators/misc'
import { query } from 'express-validator/check'
import { isValidLogLevel } from '../../helpers/custom-validators/logs'

const getLogsValidator = [
  query('startDate')
    .custom(isDateValid).withMessage('Should have a valid start date'),
  query('level')
    .optional()
    .custom(isValidLogLevel).withMessage('Should have a valid level'),
  query('endDate')
    .optional()
    .custom(isDateValid).withMessage('Should have a valid end date'),

  (req: express.Request, res: express.Response, next: express.NextFunction) => {
    logger.debug('Checking getLogsValidator parameters.', { parameters: req.query })

    if (areValidationErrors(req, res)) return

    return next()
  }
]

// ---------------------------------------------------------------------------

export {
  getLogsValidator
}