PeerTube/server/middlewares/validators/user-notifications.ts

72 lines
2.2 KiB
TypeScript
Raw Normal View History

2021-08-27 14:32:44 +02:00
import express from 'express'
2019-07-25 16:23:44 +02:00
import { body, query } from 'express-validator'
import { isNotEmptyIntArray, toBooleanOrNull } from '../../helpers/custom-validators/misc'
import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
import { areValidationErrors } from './shared'
2018-12-26 10:36:24 +01:00
const listUserNotificationsValidator = [
query('unread')
.optional()
2019-07-25 16:23:44 +02:00
.customSanitizer(toBooleanOrNull)
.isBoolean().withMessage('Should have a valid unread boolean'),
(req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return
return next()
}
]
2018-12-26 10:36:24 +01:00
const updateNotificationSettingsValidator = [
body('newVideoFromSubscription')
.custom(isUserNotificationSettingValid),
2018-12-26 10:36:24 +01:00
body('newCommentOnMyVideo')
.custom(isUserNotificationSettingValid),
2020-07-07 14:34:16 +02:00
body('abuseAsModerator')
.custom(isUserNotificationSettingValid),
body('videoAutoBlacklistAsModerator')
.custom(isUserNotificationSettingValid),
2018-12-26 10:36:24 +01:00
body('blacklistOnMyVideo')
.custom(isUserNotificationSettingValid),
body('myVideoImportFinished')
.custom(isUserNotificationSettingValid),
body('myVideoPublished')
.custom(isUserNotificationSettingValid),
body('commentMention')
.custom(isUserNotificationSettingValid),
body('newFollow')
.custom(isUserNotificationSettingValid),
body('newUserRegistration')
.custom(isUserNotificationSettingValid),
body('newInstanceFollower')
.custom(isUserNotificationSettingValid),
body('autoInstanceFollowing')
.custom(isUserNotificationSettingValid),
2018-12-26 10:36:24 +01:00
(req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return
return next()
}
]
const markAsReadUserNotificationsValidator = [
body('ids')
2019-01-08 11:26:41 +01:00
.optional()
.custom(isNotEmptyIntArray).withMessage('Should have a valid array of notification ids'),
2018-12-26 10:36:24 +01:00
(req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return
return next()
}
]
// ---------------------------------------------------------------------------
export {
listUserNotificationsValidator,
2018-12-26 10:36:24 +01:00
updateNotificationSettingsValidator,
markAsReadUserNotificationsValidator
}