aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/helpers/custom-validators/user-notifications.ts
blob: 5a4d10504e6c0812c2f33e0ac00953fbbf0d4f07 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
                               
                                 








                                                                                                           





                                                                                       





                                 
import { exists } from './misc'
import validator from 'validator'
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) &&
    validator.isInt('' + value) && (
      value === UserNotificationSettingValue.NONE ||
      value === UserNotificationSettingValue.WEB ||
      value === UserNotificationSettingValue.EMAIL ||
      value === (UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL)
    )
}

export {
  isUserNotificationSettingValid,
  isUserNotificationTypeValid
}