PeerTube/server/helpers/custom-validators/user-notifications.ts

24 lines
846 B
TypeScript
Raw Normal View History

2018-12-26 10:36:24 +01:00
import { exists } from './misc'
2020-01-07 14:56:07 +01:00
import validator from 'validator'
2018-12-26 10:36:24 +01:00
import { UserNotificationType } from '../../../shared/models/users'
import { UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model'
function isUserNotificationTypeValid (value: any) {
return exists(value) && validator.isInt('' + value) && UserNotificationType[value] !== undefined
}
function isUserNotificationSettingValid (value: any) {
return exists(value) &&
2019-01-08 11:26:41 +01:00
validator.isInt('' + value) && (
value === UserNotificationSettingValue.NONE ||
value === UserNotificationSettingValue.WEB ||
value === UserNotificationSettingValue.EMAIL ||
value === (UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL)
)
2018-12-26 10:36:24 +01:00
}
export {
isUserNotificationSettingValid,
isUserNotificationTypeValid
}