diff --git a/projects/ucap-webmessenger-app/src/app/layouts/native/components/top-bar.component.ts b/projects/ucap-webmessenger-app/src/app/layouts/native/components/top-bar.component.ts index d2bb2e86..15afa938 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/native/components/top-bar.component.ts +++ b/projects/ucap-webmessenger-app/src/app/layouts/native/components/top-bar.component.ts @@ -29,7 +29,6 @@ import { KEY_URL_INFO, LoginInfo, KEY_LOGIN_INFO, - KEY_LOGIN_RES_INFO, KEY_VER_INFO } from '@app/types'; import { @@ -100,7 +99,6 @@ export class TopBarComponent implements OnInit, OnDestroy { private sessionStorageService: SessionStorageService, private daesangApiService: DaesangApiService, private daesangProtocolService: DaesangProtocolService, - private changeDetectorRef: ChangeDetectorRef, @Inject(DOCUMENT) private document: Document, private logger: NGXLogger ) {} @@ -123,7 +121,7 @@ export class TopBarComponent implements OnInit, OnDestroy { >(KEY_VER_INFO); // WebLink init.. - this.initWebLink(); + this.initWebLink(loginRes); }) ) .subscribe(); @@ -161,85 +159,83 @@ export class TopBarComponent implements OnInit, OnDestroy { } } - initWebLink(): void { - const loginRes = this.sessionStorageService.get( - KEY_LOGIN_RES_INFO - ); + initWebLink(loginRes: LoginResponse): void { + if (!!loginRes) { + const urlInfo: DaesangUrlInfoResponse = this.sessionStorageService.get< + DaesangUrlInfoResponse + >(KEY_URL_INFO); - const urlInfo: DaesangUrlInfoResponse = this.sessionStorageService.get< - DaesangUrlInfoResponse - >(KEY_URL_INFO); - - if (!!urlInfo && !!urlInfo.webLink) { - // order by webLinkAllowedList.. - this.weblink = urlInfo.webLinkAllowedList.map(showWeblink => - urlInfo.webLink.find(weblink => weblink.key === showWeblink) - ); - - if (urlInfo.webLinkAllowedList.indexOf(WebLinkType.Mail) > -1) { - // 메일 카운트 체크. - const link = urlInfo.webLink.filter( - weblink => weblink.key === WebLinkType.MailCnt + if (!!urlInfo && !!urlInfo.webLink) { + // order by webLinkAllowedList.. + this.weblink = urlInfo.webLinkAllowedList.map(showWeblink => + urlInfo.webLink.find(weblink => weblink.key === showWeblink) ); - if (link.length > 0) { - const appUserInfo = this.localStorageService.encGet( - KEY_APP_USER_INFO, - environment.customConfig.appKey + + if (urlInfo.webLinkAllowedList.indexOf(WebLinkType.Mail) > -1) { + // 메일 카운트 체크. + const link = urlInfo.webLink.filter( + weblink => weblink.key === WebLinkType.MailCnt ); + if (link.length > 0) { + const appUserInfo = this.localStorageService.encGet( + KEY_APP_USER_INFO, + environment.customConfig.appKey + ); - const WebLinkMailCnt = link[0]; - const loginPw = appUserInfo.loginPw; - const loginPw2 = this.loginInfo.loginPw; - const loginId = this.loginInfo.loginId; - const token = loginRes.tokenString; + const WebLinkMailCnt = link[0]; + const loginPw = appUserInfo.loginPw; + const loginPw2 = this.loginInfo.loginPw; + const loginId = this.loginInfo.loginId; + const token = loginRes.tokenString; - const url = WebLinkMailCnt.url - .replace(/(\(%USER_TOKEN%\))/g, token) - .replace(/(\(%USER_ID%\))/g, loginId) - .replace(/(\(%USER_PASS%\))/g, loginPw); + const url = WebLinkMailCnt.url + .replace(/(\(%USER_TOKEN%\))/g, token) + .replace(/(\(%USER_ID%\))/g, loginId) + .replace(/(\(%USER_PASS%\))/g, loginPw); - this.daesangApiService - .retrieveMailCount(url) - .pipe( - take(1), - map(res => (this.webLinkBadgeMail = res.count)), - catchError(error => of(this.logger.log(error))) - ) - .subscribe(); + this.daesangApiService + .retrieveMailCount(url) + .pipe( + take(1), + map(res => (this.webLinkBadgeMail = res.count)), + catchError(error => of(this.logger.log(error))) + ) + .subscribe(); + } } - } - if (urlInfo.webLinkAllowedList.indexOf(WebLinkType.Payment) > -1) { - // 결제 카운트 체크. - const link = urlInfo.webLink.filter( - weblink => weblink.key === WebLinkType.PaymentCnt - ); - if (link.length > 0) { - const appUserInfo = this.localStorageService.encGet( - KEY_APP_USER_INFO, - environment.customConfig.appKey + if (urlInfo.webLinkAllowedList.indexOf(WebLinkType.Payment) > -1) { + // 결제 카운트 체크. + const link = urlInfo.webLink.filter( + weblink => weblink.key === WebLinkType.PaymentCnt ); + if (link.length > 0) { + const appUserInfo = this.localStorageService.encGet( + KEY_APP_USER_INFO, + environment.customConfig.appKey + ); - const WebLinkPaymentCnt = link[0]; - const loginPw = appUserInfo.loginPw; - const loginPw2 = this.loginInfo.loginPw; - const loginId = this.loginInfo.loginId; - const token = loginRes.tokenString; + const WebLinkPaymentCnt = link[0]; + const loginPw = appUserInfo.loginPw; + const loginPw2 = this.loginInfo.loginPw; + const loginId = this.loginInfo.loginId; + const token = loginRes.tokenString; - const url = WebLinkPaymentCnt.url - .replace(/(\(%USER_TOKEN%\))/g, token) - .replace(/(\(%USER_ID%\))/g, loginId) - .replace(/(\(%USER_PASS%\))/g, loginPw); + const url = WebLinkPaymentCnt.url + .replace(/(\(%USER_TOKEN%\))/g, token) + .replace(/(\(%USER_ID%\))/g, loginId) + .replace(/(\(%USER_PASS%\))/g, loginPw); - this.daesangApiService - .retrievePaymentCount(url) - .pipe( - take(1), - map(res => { - this.webLinkBadgePayment = res.count; - }), - catchError(error => of(this.logger.log(error))) - ) - .subscribe(); + this.daesangApiService + .retrievePaymentCount(url) + .pipe( + take(1), + map(res => { + this.webLinkBadgePayment = res.count; + }), + catchError(error => of(this.logger.log(error))) + ) + .subscribe(); + } } } }