diff options
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/user-history.ts | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/server/middlewares/validators/user-history.ts b/server/middlewares/validators/user-history.ts index f9be26627..541910be5 100644 --- a/server/middlewares/validators/user-history.ts +++ b/server/middlewares/validators/user-history.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { body, query } from 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { exists, isDateValid } from '../../helpers/custom-validators/misc' | 3 | import { exists, isDateValid, isIdValid } from '../../helpers/custom-validators/misc' |
4 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
5 | import { areValidationErrors } from './shared' | 5 | import { areValidationErrors } from './shared' |
6 | 6 | ||
@@ -18,13 +18,26 @@ const userHistoryListValidator = [ | |||
18 | } | 18 | } |
19 | ] | 19 | ] |
20 | 20 | ||
21 | const userHistoryRemoveValidator = [ | 21 | const userHistoryRemoveAllValidator = [ |
22 | body('beforeDate') | 22 | body('beforeDate') |
23 | .optional() | 23 | .optional() |
24 | .custom(isDateValid).withMessage('Should have a before date that conforms to ISO 8601'), | 24 | .custom(isDateValid).withMessage('Should have a before date that conforms to ISO 8601'), |
25 | 25 | ||
26 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 26 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
27 | logger.debug('Checking userHistoryRemoveValidator parameters', { parameters: req.body }) | 27 | logger.debug('Checking userHistoryRemoveAllValidator parameters', { parameters: req.body }) |
28 | |||
29 | if (areValidationErrors(req, res)) return | ||
30 | |||
31 | return next() | ||
32 | } | ||
33 | ] | ||
34 | |||
35 | const userHistoryRemoveElementValidator = [ | ||
36 | param('videoId') | ||
37 | .custom(isIdValid).withMessage('Should have a valid video id'), | ||
38 | |||
39 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
40 | logger.debug('Checking userHistoryRemoveElementValidator parameters', { parameters: req.params }) | ||
28 | 41 | ||
29 | if (areValidationErrors(req, res)) return | 42 | if (areValidationErrors(req, res)) return |
30 | 43 | ||
@@ -36,5 +49,6 @@ const userHistoryRemoveValidator = [ | |||
36 | 49 | ||
37 | export { | 50 | export { |
38 | userHistoryListValidator, | 51 | userHistoryListValidator, |
39 | userHistoryRemoveValidator | 52 | userHistoryRemoveElementValidator, |
53 | userHistoryRemoveAllValidator | ||
40 | } | 54 | } |