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

                                                   
                                                     



                                                      

                                  




                                                                                       





                                 
import validator from 'validator'
import { UserNotificationSettingValue } from '@shared/models'
import { exists } from './misc'

function isUserNotificationTypeValid (value: any) {
  return exists(value) && validator.isInt('' + value)
}

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
}