]>
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 { logger } from '../../helpers/logger' | |
6 | import { areValidationErrors } from './shared' | |
7 | ||
8 | const listUserNotificationsValidator = [ | |
9 | query('unread') | |
10 | .optional() | |
11 | .customSanitizer(toBooleanOrNull) | |
12 | .isBoolean().withMessage('Should have a valid unread boolean'), | |
13 | ||
14 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
15 | logger.debug('Checking listUserNotificationsValidator parameters', { parameters: req.query }) | |
16 | ||
17 | if (areValidationErrors(req, res)) return | |
18 | ||
19 | return next() | |
20 | } | |
21 | ] | |
22 | ||
23 | const updateNotificationSettingsValidator = [ | |
24 | body('newVideoFromSubscription') | |
25 | .custom(isUserNotificationSettingValid).withMessage('Should have a valid new video from subscription notification setting'), | |
26 | body('newCommentOnMyVideo') | |
27 | .custom(isUserNotificationSettingValid).withMessage('Should have a valid new comment on my video notification setting'), | |
28 | body('abuseAsModerator') | |
29 | .custom(isUserNotificationSettingValid).withMessage('Should have a valid abuse as moderator notification setting'), | |
30 | body('videoAutoBlacklistAsModerator') | |
31 | .custom(isUserNotificationSettingValid).withMessage('Should have a valid video auto blacklist notification setting'), | |
32 | body('blacklistOnMyVideo') | |
33 | .custom(isUserNotificationSettingValid).withMessage('Should have a valid new blacklist on my video notification setting'), | |
34 | body('myVideoImportFinished') | |
35 | .custom(isUserNotificationSettingValid).withMessage('Should have a valid video import finished video notification setting'), | |
36 | body('myVideoPublished') | |
37 | .custom(isUserNotificationSettingValid).withMessage('Should have a valid video published notification setting'), | |
38 | body('commentMention') | |
39 | .custom(isUserNotificationSettingValid).withMessage('Should have a valid comment mention notification setting'), | |
40 | body('newFollow') | |
41 | .custom(isUserNotificationSettingValid).withMessage('Should have a valid new follow notification setting'), | |
42 | body('newUserRegistration') | |
43 | .custom(isUserNotificationSettingValid).withMessage('Should have a valid new user registration notification setting'), | |
44 | body('newInstanceFollower') | |
45 | .custom(isUserNotificationSettingValid).withMessage('Should have a valid new instance follower notification setting'), | |
46 | body('autoInstanceFollowing') | |
47 | .custom(isUserNotificationSettingValid).withMessage('Should have a valid new instance following notification setting'), | |
48 | ||
49 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
50 | logger.debug('Checking updateNotificationSettingsValidator parameters', { parameters: req.body }) | |
51 | ||
52 | if (areValidationErrors(req, res)) return | |
53 | ||
54 | return next() | |
55 | } | |
56 | ] | |
57 | ||
58 | const markAsReadUserNotificationsValidator = [ | |
59 | body('ids') | |
60 | .optional() | |
61 | .custom(isNotEmptyIntArray).withMessage('Should have a valid notification ids to mark as read'), | |
62 | ||
63 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
64 | logger.debug('Checking markAsReadUserNotificationsValidator parameters', { parameters: req.body }) | |
65 | ||
66 | if (areValidationErrors(req, res)) return | |
67 | ||
68 | return next() | |
69 | } | |
70 | ] | |
71 | ||
72 | // --------------------------------------------------------------------------- | |
73 | ||
74 | export { | |
75 | listUserNotificationsValidator, | |
76 | updateNotificationSettingsValidator, | |
77 | markAsReadUserNotificationsValidator | |
78 | } |