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

24 lines
721 B
TypeScript
Raw Normal View History

2020-01-07 14:56:07 +01:00
import validator from 'validator'
import { UserNotificationSettingValue } from '@peertube/peertube-models'
import { exists } from './misc.js'
2018-12-26 10:36:24 +01:00
function isUserNotificationTypeValid (value: any) {
return exists(value) && validator.default.isInt('' + value)
2018-12-26 10:36:24 +01:00
}
function isUserNotificationSettingValid (value: any) {
return exists(value) &&
validator.default.isInt('' + value) &&
2020-01-31 16:56:52 +01:00
(
2019-01-08 11:26:41 +01:00
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
}