From c6dd26dcee5de3ccb19299a03f3866ac36e70831 Mon Sep 17 00:00:00 2001 From: argirok Date: Tue, 19 Dec 2023 17:20:01 +0200 Subject: [PATCH] [angular-16-irish-monitor | DONE | CHANGED] UserProfile service: update initialize method - not initialize in constructor --- services/userProfile.service.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/services/userProfile.service.ts b/services/userProfile.service.ts index 56c13c3e..f16bd788 100644 --- a/services/userProfile.service.ts +++ b/services/userProfile.service.ts @@ -21,9 +21,8 @@ export class UserProfile{ }) export class UserProfileService { private subscription; - private readonly getUserProfileSubject: AdvancedAsyncSubject = new AdvancedAsyncSubject(); + private readonly userProfileSubject: AdvancedAsyncSubject = new AdvancedAsyncSubject(); constructor(private http: HttpClient) { - this.updateUserProfile(); } clearSubscriptions() { @@ -34,26 +33,27 @@ export class UserProfileService { } public get user(): UserProfile { - return this.getUserProfileSubject.getValue(); + return this.userProfileSubject.getValue(); } public getUserProfile(): Observable { - return this.getUserProfileSubject.asObservable(); + return this.userProfileSubject.asObservable(); } public setUserProfile(userProfile:UserProfile) { - this.getUserProfileSubject.next(userProfile); + this.userProfileSubject.next(userProfile?userProfile:new UserProfile(false)); } - public updateUserProfile(resolve: Function = null) { + public initUserProfile(resolve: Function = null) { + this.subscription = this.http.get(properties.monitorServiceAPIURL + 'user', CustomOptions.registryOptions()).pipe(map(userProfile => { return userProfile; })).subscribe(user => { - this.getUserProfileSubject.next(user); + this.userProfileSubject.next(user); if (resolve) { resolve(); } }, error => { - this.getUserProfileSubject.next(null); + this.userProfileSubject.next(new UserProfile(false)); if (resolve) { resolve(); }