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

72 lines
2.2 KiB
TypeScript
Raw Normal View History

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