]>
Commit | Line | Data |
---|---|---|
41fb13c3 | 1 | import express from 'express' |
c8861d5d | 2 | import { query } from 'express-validator' |
64553e88 | 3 | import { isStringArray } from '@server/helpers/custom-validators/search' |
fd8710b8 | 4 | import { isValidLogLevel } from '../../helpers/custom-validators/logs' |
64553e88 | 5 | import { isDateValid, toArray } from '../../helpers/custom-validators/misc' |
10363c74 C |
6 | import { logger } from '../../helpers/logger' |
7 | import { areValidationErrors } from './shared' | |
fd8710b8 C |
8 | |
9 | const getLogsValidator = [ | |
10 | query('startDate') | |
70330f63 | 11 | .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'), |
fd8710b8 C |
12 | query('level') |
13 | .optional() | |
14 | .custom(isValidLogLevel).withMessage('Should have a valid level'), | |
64553e88 C |
15 | query('tagsOneOf') |
16 | .optional() | |
17 | .customSanitizer(toArray) | |
18 | .custom(isStringArray).withMessage('Should have a valid one of tags array'), | |
fd8710b8 C |
19 | query('endDate') |
20 | .optional() | |
70330f63 | 21 | .custom(isDateValid).withMessage('Should have an end date that conforms to ISO 8601'), |
fd8710b8 C |
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 | ||
566c125d C |
32 | const getAuditLogsValidator = [ |
33 | query('startDate') | |
70330f63 | 34 | .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'), |
566c125d C |
35 | query('endDate') |
36 | .optional() | |
70330f63 | 37 | .custom(isDateValid).withMessage('Should have a end date that conforms to ISO 8601'), |
566c125d C |
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 | ||
fd8710b8 C |
48 | // --------------------------------------------------------------------------- |
49 | ||
50 | export { | |
566c125d C |
51 | getLogsValidator, |
52 | getAuditLogsValidator | |
fd8710b8 | 53 | } |