]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/user-notifications.ts
Type toActivityPubObject functions
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / user-notifications.ts
CommitLineData
cef534ed 1import * as express from 'express'
c8861d5d 2import { body, query } from 'express-validator'
cef534ed
C
3import { logger } from '../../helpers/logger'
4import { areValidationErrors } from './utils'
5import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
c8861d5d 6import { isNotEmptyIntArray, toBooleanOrNull } from '../../helpers/custom-validators/misc'
cef534ed 7
dc133480
C
8const listUserNotificationsValidator = [
9 query('unread')
10 .optional()
c8861d5d 11 .customSanitizer(toBooleanOrNull)
dc133480
C
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
cef534ed
C
23const 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('videoAbuseAsModerator')
29 .custom(isUserNotificationSettingValid).withMessage('Should have a valid new video abuse as moderator notification setting'),
883993c8
C
30 body('videoAutoBlacklistAsModerator')
31 .custom(isUserNotificationSettingValid).withMessage('Should have a valid video auto blacklist notification setting'),
cef534ed
C
32 body('blacklistOnMyVideo')
33 .custom(isUserNotificationSettingValid).withMessage('Should have a valid new blacklist on my video notification setting'),
883993c8
C
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'),
cef534ed
C
46
47 (req: express.Request, res: express.Response, next: express.NextFunction) => {
48 logger.debug('Checking updateNotificationSettingsValidator parameters', { parameters: req.body })
49
50 if (areValidationErrors(req, res)) return
51
52 return next()
53 }
54]
55
56const markAsReadUserNotificationsValidator = [
57 body('ids')
2f1548fd
C
58 .optional()
59 .custom(isNotEmptyIntArray).withMessage('Should have a valid notification ids to mark as read'),
cef534ed
C
60
61 (req: express.Request, res: express.Response, next: express.NextFunction) => {
62 logger.debug('Checking markAsReadUserNotificationsValidator parameters', { parameters: req.body })
63
64 if (areValidationErrors(req, res)) return
65
66 return next()
67 }
68]
69
70// ---------------------------------------------------------------------------
71
72export {
dc133480 73 listUserNotificationsValidator,
cef534ed
C
74 updateNotificationSettingsValidator,
75 markAsReadUserNotificationsValidator
76}