[angular-16-irish-monitor | DONE | CHANGED] UserProfile service: update initialize method - not initialize in constructor

This commit is contained in:
argirok 2023-12-19 17:20:01 +02:00
parent 8f009f3fee
commit c6dd26dcee
1 changed files with 8 additions and 8 deletions

View File

@ -21,9 +21,8 @@ export class UserProfile{
}) })
export class UserProfileService { export class UserProfileService {
private subscription; private subscription;
private readonly getUserProfileSubject: AdvancedAsyncSubject<UserProfile> = new AdvancedAsyncSubject<UserProfile>(); private readonly userProfileSubject: AdvancedAsyncSubject<UserProfile> = new AdvancedAsyncSubject<UserProfile>();
constructor(private http: HttpClient) { constructor(private http: HttpClient) {
this.updateUserProfile();
} }
clearSubscriptions() { clearSubscriptions() {
@ -34,26 +33,27 @@ export class UserProfileService {
} }
public get user(): UserProfile { public get user(): UserProfile {
return this.getUserProfileSubject.getValue(); return this.userProfileSubject.getValue();
} }
public getUserProfile(): Observable<UserProfile> { public getUserProfile(): Observable<UserProfile> {
return this.getUserProfileSubject.asObservable(); return this.userProfileSubject.asObservable();
} }
public setUserProfile(userProfile:UserProfile) { 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<UserProfile>(properties.monitorServiceAPIURL + 'user', CustomOptions.registryOptions()).pipe(map(userProfile => { this.subscription = this.http.get<UserProfile>(properties.monitorServiceAPIURL + 'user', CustomOptions.registryOptions()).pipe(map(userProfile => {
return userProfile; return userProfile;
})).subscribe(user => { })).subscribe(user => {
this.getUserProfileSubject.next(user); this.userProfileSubject.next(user);
if (resolve) { if (resolve) {
resolve(); resolve();
} }
}, error => { }, error => {
this.getUserProfileSubject.next(null); this.userProfileSubject.next(new UserProfile(false));
if (resolve) { if (resolve) {
resolve(); resolve();
} }