/* eslint-disable class-methods-use-this */ import init from '@utils/instance'; import Action from '@actions'; import isNil from 'lodash/isNil'; const userInstance = init(); class UserCache { userData: any; permissionData: any; constructor() { const instance = userInstance(); if (instance) return instance; this.userData = null; this.permissionData = null; userInstance(this); } get user() { return this.userData; // const u = Store.get(CK.USER_INFO); // return u ? JSON.parse(u) : null; } set user(value) { this.userData = value; // if (value === null) { // Store.remove(CK.USER_INFO); // } // Store.expireSet(CK.USER_INFO, JSON.stringify(value), expireUser()); } get permission() { return this.permissionData; // const u = Store.expireGet(CK.USER_PERMISSION); // return u ? JSON.parse(u) : null; } set permission(value) { this.permissionData = value; // if (value === null) { // Store.remove(CK.USER_PERMISSION); // } // Store.expireSet(CK.USER_PERMISSION, JSON.stringify(value), expireUser()); } login = (user: {username: string; password: string}) => { if (!user) return; const {username, password} = user || {}; Action.emit('user.login', {username, password, gatewayToken: true}); }; hasBrokerAuth = () => { if (isNil(this.permission)) return false; const {authzedBondBrokers, authzedNcdBrokers} = this.permission; return authzedBondBrokers.length !== 0 || authzedNcdBrokers.length !== 0; }; auth = (no: string) => { if (!this.permission || !this.permission.bondCdcAuthzMap) { return false; } const {bondCdcAuthzMap} = this.permission; if (['1', '2', '3', '4', '5', '6'].indexOf(no) > -1) { return bondCdcAuthzMap[no] ? bondCdcAuthzMap[no].cdcPermission || false : false; } switch (no) { case '7': return this.permission.cdcValAffiliateYtd; case '8': return this.permission.cdcCurveYtd; case '9': return this.permission.cdcCurveHis; case '10': return this.permission.cdcValHis; default: return true; } }; csi = () => { if (!this.permission) { return false; } return !!this.permission.csiVal; }; } export default new UserCache();