diff options
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/user-notifications.ts | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/server/middlewares/validators/user-notifications.ts b/server/middlewares/validators/user-notifications.ts index 8202f307e..1c31f0a73 100644 --- a/server/middlewares/validators/user-notifications.ts +++ b/server/middlewares/validators/user-notifications.ts | |||
@@ -1,11 +1,26 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { body } from 'express-validator/check' | 3 | import { body, query } from 'express-validator/check' |
4 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
5 | import { areValidationErrors } from './utils' | 5 | import { areValidationErrors } from './utils' |
6 | import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' | 6 | import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' |
7 | import { isIntArray } from '../../helpers/custom-validators/misc' | 7 | import { isIntArray } from '../../helpers/custom-validators/misc' |
8 | 8 | ||
9 | const listUserNotificationsValidator = [ | ||
10 | query('unread') | ||
11 | .optional() | ||
12 | .toBoolean() | ||
13 | .isBoolean().withMessage('Should have a valid unread boolean'), | ||
14 | |||
15 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
16 | logger.debug('Checking listUserNotificationsValidator parameters', { parameters: req.query }) | ||
17 | |||
18 | if (areValidationErrors(req, res)) return | ||
19 | |||
20 | return next() | ||
21 | } | ||
22 | ] | ||
23 | |||
9 | const updateNotificationSettingsValidator = [ | 24 | const updateNotificationSettingsValidator = [ |
10 | body('newVideoFromSubscription') | 25 | body('newVideoFromSubscription') |
11 | .custom(isUserNotificationSettingValid).withMessage('Should have a valid new video from subscription notification setting'), | 26 | .custom(isUserNotificationSettingValid).withMessage('Should have a valid new video from subscription notification setting'), |
@@ -41,6 +56,7 @@ const markAsReadUserNotificationsValidator = [ | |||
41 | // --------------------------------------------------------------------------- | 56 | // --------------------------------------------------------------------------- |
42 | 57 | ||
43 | export { | 58 | export { |
59 | listUserNotificationsValidator, | ||
44 | updateNotificationSettingsValidator, | 60 | updateNotificationSettingsValidator, |
45 | markAsReadUserNotificationsValidator | 61 | markAsReadUserNotificationsValidator |
46 | } | 62 | } |