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'
7 const listUserNotificationsValidator = [
10 .customSanitizer(toBooleanOrNull)
11 .isBoolean().withMessage('Should have a valid unread boolean'),
13 (req: express.Request, res: express.Response, next: express.NextFunction) => {
14 if (areValidationErrors(req, res)) return
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),
38 .custom(isUserNotificationSettingValid),
39 body('newUserRegistration')
40 .custom(isUserNotificationSettingValid),
41 body('newInstanceFollower')
42 .custom(isUserNotificationSettingValid),
43 body('autoInstanceFollowing')
44 .custom(isUserNotificationSettingValid),
46 (req: express.Request, res: express.Response, next: express.NextFunction) => {
47 if (areValidationErrors(req, res)) return
53 const markAsReadUserNotificationsValidator = [
56 .custom(isNotEmptyIntArray).withMessage('Should have a valid array of notification ids'),
58 (req: express.Request, res: express.Response, next: express.NextFunction) => {
59 if (areValidationErrors(req, res)) return
65 // ---------------------------------------------------------------------------
68 listUserNotificationsValidator,
69 updateNotificationSettingsValidator,
70 markAsReadUserNotificationsValidator