PeerTube/server/middlewares/validators/logs.ts

49 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-04-10 15:26:33 +02:00
import * as express from 'express'
import { logger } from '../../helpers/logger'
import { areValidationErrors } from './utils'
import { isDateValid } from '../../helpers/custom-validators/misc'
2019-07-25 16:23:44 +02:00
import { query } from 'express-validator'
2019-04-10 15:26:33 +02:00
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()
}
]
2019-12-11 14:14:01 +01:00
const getAuditLogsValidator = [
query('startDate')
.custom(isDateValid).withMessage('Should have a valid start date'),
query('endDate')
.optional()
.custom(isDateValid).withMessage('Should have a valid end date'),
(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 15:26:33 +02:00
// ---------------------------------------------------------------------------
export {
2019-12-11 14:14:01 +01:00
getLogsValidator,
getAuditLogsValidator
2019-04-10 15:26:33 +02:00
}