]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/validators/user-notifications.ts
Add user notification base code
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / user-notifications.ts
1 import * as express from 'express'
2 import 'express-validator'
3 import { body } 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 { isIntArray } from '../../helpers/custom-validators/misc'
8
9 const updateNotificationSettingsValidator = [
10 body('newVideoFromSubscription')
11 .custom(isUserNotificationSettingValid).withMessage('Should have a valid new video from subscription notification setting'),
12 body('newCommentOnMyVideo')
13 .custom(isUserNotificationSettingValid).withMessage('Should have a valid new comment on my video notification setting'),
14 body('videoAbuseAsModerator')
15 .custom(isUserNotificationSettingValid).withMessage('Should have a valid new video abuse as moderator notification setting'),
16 body('blacklistOnMyVideo')
17 .custom(isUserNotificationSettingValid).withMessage('Should have a valid new blacklist on my video notification setting'),
18
19 (req: express.Request, res: express.Response, next: express.NextFunction) => {
20 logger.debug('Checking updateNotificationSettingsValidator parameters', { parameters: req.body })
21
22 if (areValidationErrors(req, res)) return
23
24 return next()
25 }
26 ]
27
28 const markAsReadUserNotificationsValidator = [
29 body('ids')
30 .custom(isIntArray).withMessage('Should have a valid notification ids to mark as read'),
31
32 (req: express.Request, res: express.Response, next: express.NextFunction) => {
33 logger.debug('Checking markAsReadUserNotificationsValidator parameters', { parameters: req.body })
34
35 if (areValidationErrors(req, res)) return
36
37 return next()
38 }
39 ]
40
41 // ---------------------------------------------------------------------------
42
43 export {
44 updateNotificationSettingsValidator,
45 markAsReadUserNotificationsValidator
46 }