]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/user-notifications.ts
Cleanup useless express validator messages
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / user-notifications.ts
CommitLineData
41fb13c3 1import express from 'express'
c8861d5d 2import { body, query } from 'express-validator'
c8861d5d 3import { isNotEmptyIntArray, toBooleanOrNull } from '../../helpers/custom-validators/misc'
10363c74
C
4import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
5import { logger } from '../../helpers/logger'
6import { areValidationErrors } from './shared'
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')
396f6f01 25 .custom(isUserNotificationSettingValid),
cef534ed 26 body('newCommentOnMyVideo')
396f6f01 27 .custom(isUserNotificationSettingValid),
4f32032f 28 body('abuseAsModerator')
396f6f01 29 .custom(isUserNotificationSettingValid),
883993c8 30 body('videoAutoBlacklistAsModerator')
396f6f01 31 .custom(isUserNotificationSettingValid),
cef534ed 32 body('blacklistOnMyVideo')
396f6f01 33 .custom(isUserNotificationSettingValid),
883993c8 34 body('myVideoImportFinished')
396f6f01 35 .custom(isUserNotificationSettingValid),
883993c8 36 body('myVideoPublished')
396f6f01 37 .custom(isUserNotificationSettingValid),
883993c8 38 body('commentMention')
396f6f01 39 .custom(isUserNotificationSettingValid),
883993c8 40 body('newFollow')
396f6f01 41 .custom(isUserNotificationSettingValid),
883993c8 42 body('newUserRegistration')
396f6f01 43 .custom(isUserNotificationSettingValid),
883993c8 44 body('newInstanceFollower')
396f6f01 45 .custom(isUserNotificationSettingValid),
8424c402 46 body('autoInstanceFollowing')
396f6f01 47 .custom(isUserNotificationSettingValid),
cef534ed
C
48
49 (req: express.Request, res: express.Response, next: express.NextFunction) => {
50 logger.debug('Checking updateNotificationSettingsValidator parameters', { parameters: req.body })
51
52 if (areValidationErrors(req, res)) return
53
54 return next()
55 }
56]
57
58const markAsReadUserNotificationsValidator = [
59 body('ids')
2f1548fd 60 .optional()
396f6f01 61 .custom(isNotEmptyIntArray).withMessage('Should have a valid array of notification ids'),
cef534ed
C
62
63 (req: express.Request, res: express.Response, next: express.NextFunction) => {
64 logger.debug('Checking markAsReadUserNotificationsValidator parameters', { parameters: req.body })
65
66 if (areValidationErrors(req, res)) return
67
68 return next()
69 }
70]
71
72// ---------------------------------------------------------------------------
73
74export {
dc133480 75 listUserNotificationsValidator,
cef534ed
C
76 updateNotificationSettingsValidator,
77 markAsReadUserNotificationsValidator
78}