import { Column } from 'typeorm' ; import { intersect , difference } from '../helpers/helpers' ; import { getAllAllowedVerifications } from '../services/external/verify.action.service' ; export enum Notifications { USER_SIGNIN = 'user_signin' , USER_CHANGE_PASSWORD = 'user_change_password' , USER_CHANGE_PAYMENT_PASSWORD = 'user_change_payment_password' , USER_RESET_PASSWORD = 'user_reset_password' } export function getAllNotifications ( ) { return [ Notifications . USER_SIGNIN , Notifications . USER_CHANGE_PASSWORD , Notifications . USER_CHANGE_PAYMENT_PASSWORD , Notifications . USER_RESET_PASSWORD ] ; } export type BooleanState = { [ k ] : boolean ; } ; function setState ( allowedKeys , passedState ) { return allowedKeys . reduce ( ( state , name ) => { state [ name ] = passedState [ name ] === undefined || ! ! passedState [ name ] ; return state ; } , { } ) ; } export class Preferences { @ Column ( ) notifications : BooleanState = { } ; @ Column ( ) verifications : BooleanState = { } ; setNotifications ( notifications ) { this . notifications = setState ( getAllNotifications ( ) , notifications ) ; } setVerifications ( verifications ) { this . verifications = setState ( getAllAllowedVerifications ( ) , verifications ) ; } }