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