]>
Commit | Line | Data |
---|---|---|
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 | ||
9 | const getLogsValidator = [ | |
10 | query('startDate') | |
11 | .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'), | |
12 | query('level') | |
13 | .optional() | |
14 | .custom(isValidLogLevel).withMessage('Should have a valid level'), | |
15 | query('tagsOneOf') | |
16 | .optional() | |
17 | .customSanitizer(toArray) | |
18 | .custom(isStringArray).withMessage('Should have a valid one of tags array'), | |
19 | query('endDate') | |
20 | .optional() | |
21 | .custom(isDateValid).withMessage('Should have an end date that conforms to ISO 8601'), | |
22 | ||
23 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
24 | logger.debug('Checking getLogsValidator parameters.', { parameters: req.query }) | |
25 | ||
26 | if (areValidationErrors(req, res)) return | |
27 | ||
28 | return next() | |
29 | } | |
30 | ] | |
31 | ||
32 | const getAuditLogsValidator = [ | |
33 | query('startDate') | |
34 | .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'), | |
35 | query('endDate') | |
36 | .optional() | |
37 | .custom(isDateValid).withMessage('Should have a end date that conforms to ISO 8601'), | |
38 | ||
39 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
40 | logger.debug('Checking getAuditLogsValidator parameters.', { parameters: req.query }) | |
41 | ||
42 | if (areValidationErrors(req, res)) return | |
43 | ||
44 | return next() | |
45 | } | |
46 | ] | |
47 | ||
48 | // --------------------------------------------------------------------------- | |
49 | ||
50 | export { | |
51 | getLogsValidator, | |
52 | getAuditLogsValidator | |
53 | } |