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