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'
|
2021-06-03 17:33:44 +02:00
|
|
|
import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
|
|
|
|
import { areValidationErrors } from './shared'
|
2018-12-26 10:36:24 +01:00
|
|
|
|
2019-01-02 16:37:43 +01:00
|
|
|
const listUserNotificationsValidator = [
|
|
|
|
query('unread')
|
|
|
|
.optional()
|
2019-07-25 16:23:44 +02:00
|
|
|
.customSanitizer(toBooleanOrNull)
|
2019-01-02 16:37:43 +01:00
|
|
|
.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')
|
2022-08-17 14:27:04 +02:00
|
|
|
.custom(isUserNotificationSettingValid),
|
2018-12-26 10:36:24 +01:00
|
|
|
body('newCommentOnMyVideo')
|
2022-08-17 14:27:04 +02:00
|
|
|
.custom(isUserNotificationSettingValid),
|
2020-07-07 14:34:16 +02:00
|
|
|
body('abuseAsModerator')
|
2022-08-17 14:27:04 +02:00
|
|
|
.custom(isUserNotificationSettingValid),
|
2019-04-08 17:26:01 +02:00
|
|
|
body('videoAutoBlacklistAsModerator')
|
2022-08-17 14:27:04 +02:00
|
|
|
.custom(isUserNotificationSettingValid),
|
2018-12-26 10:36:24 +01:00
|
|
|
body('blacklistOnMyVideo')
|
2022-08-17 14:27:04 +02:00
|
|
|
.custom(isUserNotificationSettingValid),
|
2019-04-08 17:26:01 +02:00
|
|
|
body('myVideoImportFinished')
|
2022-08-17 14:27:04 +02:00
|
|
|
.custom(isUserNotificationSettingValid),
|
2019-04-08 17:26:01 +02:00
|
|
|
body('myVideoPublished')
|
2022-08-17 14:27:04 +02:00
|
|
|
.custom(isUserNotificationSettingValid),
|
2019-04-08 17:26:01 +02:00
|
|
|
body('commentMention')
|
2022-08-17 14:27:04 +02:00
|
|
|
.custom(isUserNotificationSettingValid),
|
2019-04-08 17:26:01 +02:00
|
|
|
body('newFollow')
|
2022-08-17 14:27:04 +02:00
|
|
|
.custom(isUserNotificationSettingValid),
|
2019-04-08 17:26:01 +02:00
|
|
|
body('newUserRegistration')
|
2022-08-17 14:27:04 +02:00
|
|
|
.custom(isUserNotificationSettingValid),
|
2019-04-08 17:26:01 +02:00
|
|
|
body('newInstanceFollower')
|
2022-08-17 14:27:04 +02:00
|
|
|
.custom(isUserNotificationSettingValid),
|
2019-08-30 16:50:12 +02:00
|
|
|
body('autoInstanceFollowing')
|
2022-08-17 14:27:04 +02:00
|
|
|
.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()
|
2022-08-17 14:27:04 +02:00
|
|
|
.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 {
|
2019-01-02 16:37:43 +01:00
|
|
|
listUserNotificationsValidator,
|
2018-12-26 10:36:24 +01:00
|
|
|
updateNotificationSettingsValidator,
|
|
|
|
markAsReadUserNotificationsValidator
|
|
|
|
}
|