1 import * as express from 'express'
2 import 'express-validator'
3 import { body, query } from 'express-validator/check'
4 import { logger } from '../../helpers/logger'
5 import { areValidationErrors } from './utils'
6 import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
7 import { isNotEmptyIntArray } from '../../helpers/custom-validators/misc'
9 const listUserNotificationsValidator = [
13 .isBoolean().withMessage('Should have a valid unread boolean'),
15 (req: express.Request, res: express.Response, next: express.NextFunction) => {
16 logger.debug('Checking listUserNotificationsValidator parameters', { parameters: req.query })
18 if (areValidationErrors(req, res)) return
24 const updateNotificationSettingsValidator = [
25 body('newVideoFromSubscription')
26 .custom(isUserNotificationSettingValid).withMessage('Should have a valid new video from subscription notification setting'),
27 body('newCommentOnMyVideo')
28 .custom(isUserNotificationSettingValid).withMessage('Should have a valid new comment on my video notification setting'),
29 body('videoAbuseAsModerator')
30 .custom(isUserNotificationSettingValid).withMessage('Should have a valid new video abuse as moderator notification setting'),
31 body('videoAutoBlacklistAsModerator')
32 .custom(isUserNotificationSettingValid).withMessage('Should have a valid video auto blacklist notification setting'),
33 body('blacklistOnMyVideo')
34 .custom(isUserNotificationSettingValid).withMessage('Should have a valid new blacklist on my video notification setting'),
35 body('myVideoImportFinished')
36 .custom(isUserNotificationSettingValid).withMessage('Should have a valid video import finished video notification setting'),
37 body('myVideoPublished')
38 .custom(isUserNotificationSettingValid).withMessage('Should have a valid video published notification setting'),
39 body('commentMention')
40 .custom(isUserNotificationSettingValid).withMessage('Should have a valid comment mention notification setting'),
42 .custom(isUserNotificationSettingValid).withMessage('Should have a valid new follow notification setting'),
43 body('newUserRegistration')
44 .custom(isUserNotificationSettingValid).withMessage('Should have a valid new user registration notification setting'),
45 body('newInstanceFollower')
46 .custom(isUserNotificationSettingValid).withMessage('Should have a valid new instance follower notification setting'),
48 (req: express.Request, res: express.Response, next: express.NextFunction) => {
49 logger.debug('Checking updateNotificationSettingsValidator parameters', { parameters: req.body })
51 if (areValidationErrors(req, res)) return
57 const markAsReadUserNotificationsValidator = [
60 .custom(isNotEmptyIntArray).withMessage('Should have a valid notification ids to mark as read'),
62 (req: express.Request, res: express.Response, next: express.NextFunction) => {
63 logger.debug('Checking markAsReadUserNotificationsValidator parameters', { parameters: req.body })
65 if (areValidationErrors(req, res)) return
71 // ---------------------------------------------------------------------------
74 listUserNotificationsValidator,
75 updateNotificationSettingsValidator,
76 markAsReadUserNotificationsValidator