diff options
Diffstat (limited to 'server/middlewares/validators/logs.ts')
-rw-r--r-- | server/middlewares/validators/logs.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/server/middlewares/validators/logs.ts b/server/middlewares/validators/logs.ts new file mode 100644 index 000000000..7380c6edd --- /dev/null +++ b/server/middlewares/validators/logs.ts | |||
@@ -0,0 +1,31 @@ | |||
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 | |||
8 | const getLogsValidator = [ | ||
9 | query('startDate') | ||
10 | .custom(isDateValid).withMessage('Should have a valid start date'), | ||
11 | query('level') | ||
12 | .optional() | ||
13 | .custom(isValidLogLevel).withMessage('Should have a valid level'), | ||
14 | query('endDate') | ||
15 | .optional() | ||
16 | .custom(isDateValid).withMessage('Should have a valid end date'), | ||
17 | |||
18 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
19 | logger.debug('Checking getLogsValidator parameters.', { parameters: req.query }) | ||
20 | |||
21 | if (areValidationErrors(req, res)) return | ||
22 | |||
23 | return next() | ||
24 | } | ||
25 | ] | ||
26 | |||
27 | // --------------------------------------------------------------------------- | ||
28 | |||
29 | export { | ||
30 | getLogsValidator | ||
31 | } | ||