1
0
Fork 0
peertube/server/middlewares/validators/user-notifications.ts

72 lines
2.2 KiB
TypeScript
Raw Normal View History

2021-08-27 08:32:44 -04:00
import express from 'express'
2019-07-25 10:23:44 -04: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 04:36:24 -05:00
const listUserNotificationsValidator = [
query('unread')
.optional()
2019-07-25 10:23:44 -04: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 04:36:24 -05:00
const updateNotificationSettingsValidator = [
body('newVideoFromSubscription')
.custom(isUserNotificationSettingValid),
2018-12-26 04:36:24 -05:00
body('newCommentOnMyVideo')
.custom(isUserNotificationSettingValid),
2020-07-07 08:34:16 -04:00
body('abuseAsModerator')
.custom(isUserNotificationSettingValid),
body('videoAutoBlacklistAsModerator')
.custom(isUserNotificationSettingValid),
2018-12-26 04:36:24 -05: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 04:36:24 -05:00
(req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return
return next()
}
]
const markAsReadUserNotificationsValidator = [
body('ids')
2019-01-08 05:26:41 -05:00
.optional()
.custom(isNotEmptyIntArray).withMessage('Should have a valid array of notification ids'),
2018-12-26 04:36:24 -05:00
(req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return
return next()
}
]
// ---------------------------------------------------------------------------
export {
listUserNotificationsValidator,
2018-12-26 04:36:24 -05:00
updateNotificationSettingsValidator,
markAsReadUserNotificationsValidator
}