2021-08-27 07:32:44 -05:00
|
|
|
import express from 'express'
|
2019-07-25 09:23:44 -05:00
|
|
|
import { query } from 'express-validator'
|
2019-04-10 08:26:33 -05:00
|
|
|
import { isValidLogLevel } from '../../helpers/custom-validators/logs'
|
2021-06-03 10:33:44 -05:00
|
|
|
import { isDateValid } from '../../helpers/custom-validators/misc'
|
|
|
|
import { logger } from '../../helpers/logger'
|
|
|
|
import { areValidationErrors } from './shared'
|
2019-04-10 08:26:33 -05:00
|
|
|
|
|
|
|
const getLogsValidator = [
|
|
|
|
query('startDate')
|
2021-05-31 12:47:14 -05:00
|
|
|
.custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
|
2019-04-10 08:26:33 -05:00
|
|
|
query('level')
|
|
|
|
.optional()
|
|
|
|
.custom(isValidLogLevel).withMessage('Should have a valid level'),
|
|
|
|
query('endDate')
|
|
|
|
.optional()
|
2021-05-31 12:47:14 -05:00
|
|
|
.custom(isDateValid).withMessage('Should have an end date that conforms to ISO 8601'),
|
2019-04-10 08:26:33 -05:00
|
|
|
|
|
|
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
logger.debug('Checking getLogsValidator parameters.', { parameters: req.query })
|
|
|
|
|
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2019-12-11 07:14:01 -06:00
|
|
|
const getAuditLogsValidator = [
|
|
|
|
query('startDate')
|
2021-05-31 12:47:14 -05:00
|
|
|
.custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
|
2019-12-11 07:14:01 -06:00
|
|
|
query('endDate')
|
|
|
|
.optional()
|
2021-05-31 12:47:14 -05:00
|
|
|
.custom(isDateValid).withMessage('Should have a end date that conforms to ISO 8601'),
|
2019-12-11 07:14:01 -06:00
|
|
|
|
|
|
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
logger.debug('Checking getAuditLogsValidator parameters.', { parameters: req.query })
|
|
|
|
|
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2019-04-10 08:26:33 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2019-12-11 07:14:01 -06:00
|
|
|
getLogsValidator,
|
|
|
|
getAuditLogsValidator
|
2019-04-10 08:26:33 -05:00
|
|
|
}
|