]>
Commit | Line | Data |
---|---|---|
41fb13c3 | 1 | import express from 'express' |
c8861d5d | 2 | import { body, query } from 'express-validator' |
c8861d5d | 3 | import { isNotEmptyIntArray, toBooleanOrNull } from '../../helpers/custom-validators/misc' |
10363c74 | 4 | import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' |
10363c74 | 5 | import { areValidationErrors } from './shared' |
cef534ed | 6 | |
dc133480 C |
7 | const listUserNotificationsValidator = [ |
8 | query('unread') | |
9 | .optional() | |
c8861d5d | 10 | .customSanitizer(toBooleanOrNull) |
dc133480 C |
11 | .isBoolean().withMessage('Should have a valid unread boolean'), |
12 | ||
13 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
dc133480 C |
14 | if (areValidationErrors(req, res)) return |
15 | ||
16 | return next() | |
17 | } | |
18 | ] | |
19 | ||
cef534ed C |
20 | const updateNotificationSettingsValidator = [ |
21 | body('newVideoFromSubscription') | |
396f6f01 | 22 | .custom(isUserNotificationSettingValid), |
cef534ed | 23 | body('newCommentOnMyVideo') |
396f6f01 | 24 | .custom(isUserNotificationSettingValid), |
4f32032f | 25 | body('abuseAsModerator') |
396f6f01 | 26 | .custom(isUserNotificationSettingValid), |
883993c8 | 27 | body('videoAutoBlacklistAsModerator') |
396f6f01 | 28 | .custom(isUserNotificationSettingValid), |
cef534ed | 29 | body('blacklistOnMyVideo') |
396f6f01 | 30 | .custom(isUserNotificationSettingValid), |
883993c8 | 31 | body('myVideoImportFinished') |
396f6f01 | 32 | .custom(isUserNotificationSettingValid), |
883993c8 | 33 | body('myVideoPublished') |
396f6f01 | 34 | .custom(isUserNotificationSettingValid), |
883993c8 | 35 | body('commentMention') |
396f6f01 | 36 | .custom(isUserNotificationSettingValid), |
883993c8 | 37 | body('newFollow') |
396f6f01 | 38 | .custom(isUserNotificationSettingValid), |
883993c8 | 39 | body('newUserRegistration') |
396f6f01 | 40 | .custom(isUserNotificationSettingValid), |
883993c8 | 41 | body('newInstanceFollower') |
396f6f01 | 42 | .custom(isUserNotificationSettingValid), |
8424c402 | 43 | body('autoInstanceFollowing') |
396f6f01 | 44 | .custom(isUserNotificationSettingValid), |
cef534ed C |
45 | |
46 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
cef534ed C |
47 | if (areValidationErrors(req, res)) return |
48 | ||
49 | return next() | |
50 | } | |
51 | ] | |
52 | ||
53 | const markAsReadUserNotificationsValidator = [ | |
54 | body('ids') | |
2f1548fd | 55 | .optional() |
396f6f01 | 56 | .custom(isNotEmptyIntArray).withMessage('Should have a valid array of notification ids'), |
cef534ed C |
57 | |
58 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
cef534ed C |
59 | if (areValidationErrors(req, res)) return |
60 | ||
61 | return next() | |
62 | } | |
63 | ] | |
64 | ||
65 | // --------------------------------------------------------------------------- | |
66 | ||
67 | export { | |
dc133480 | 68 | listUserNotificationsValidator, |
cef534ed C |
69 | updateNotificationSettingsValidator, |
70 | markAsReadUserNotificationsValidator | |
71 | } |