]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/user-notifications.ts
Add import finished and video published notifs
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / user-notifications.ts
CommitLineData
cef534ed
C
1import * as express from 'express'
2import 'express-validator'
dc133480 3import { body, query } from 'express-validator/check'
cef534ed
C
4import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils'
6import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
7import { isIntArray } from '../../helpers/custom-validators/misc'
8
dc133480
C
9const listUserNotificationsValidator = [
10 query('unread')
11 .optional()
12 .toBoolean()
13 .isBoolean().withMessage('Should have a valid unread boolean'),
14
15 (req: express.Request, res: express.Response, next: express.NextFunction) => {
16 logger.debug('Checking listUserNotificationsValidator parameters', { parameters: req.query })
17
18 if (areValidationErrors(req, res)) return
19
20 return next()
21 }
22]
23
cef534ed
C
24const 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('blacklistOnMyVideo')
32 .custom(isUserNotificationSettingValid).withMessage('Should have a valid new blacklist on my video notification setting'),
33
34 (req: express.Request, res: express.Response, next: express.NextFunction) => {
35 logger.debug('Checking updateNotificationSettingsValidator parameters', { parameters: req.body })
36
37 if (areValidationErrors(req, res)) return
38
39 return next()
40 }
41]
42
43const markAsReadUserNotificationsValidator = [
44 body('ids')
45 .custom(isIntArray).withMessage('Should have a valid notification ids to mark as read'),
46
47 (req: express.Request, res: express.Response, next: express.NextFunction) => {
48 logger.debug('Checking markAsReadUserNotificationsValidator parameters', { parameters: req.body })
49
50 if (areValidationErrors(req, res)) return
51
52 return next()
53 }
54]
55
56// ---------------------------------------------------------------------------
57
58export {
dc133480 59 listUserNotificationsValidator,
cef534ed
C
60 updateNotificationSettingsValidator,
61 markAsReadUserNotificationsValidator
62}