aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/user-notifications.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-12-26 10:36:24 +0100
committerChocobozzz <chocobozzz@cpy.re>2019-01-09 11:15:15 +0100
commitcef534ed53e4518fe0acf581bfe880788d42fc36 (patch)
tree115b51ea5136849a2336d44915c7780649f25dc2 /server/middlewares/validators/user-notifications.ts
parent1de1d05f4c61fe059fa5e24e79c92582f0e7e4b3 (diff)
downloadPeerTube-cef534ed53e4518fe0acf581bfe880788d42fc36.tar.gz
PeerTube-cef534ed53e4518fe0acf581bfe880788d42fc36.tar.zst
PeerTube-cef534ed53e4518fe0acf581bfe880788d42fc36.zip
Add user notification base code
Diffstat (limited to 'server/middlewares/validators/user-notifications.ts')
-rw-r--r--server/middlewares/validators/user-notifications.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/server/middlewares/validators/user-notifications.ts b/server/middlewares/validators/user-notifications.ts
new file mode 100644
index 000000000..8202f307e
--- /dev/null
+++ b/server/middlewares/validators/user-notifications.ts
@@ -0,0 +1,46 @@
1import * as express from 'express'
2import 'express-validator'
3import { body } from 'express-validator/check'
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
9const 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
28const 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
43export {
44 updateNotificationSettingsValidator,
45 markAsReadUserNotificationsValidator
46}