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

angular-16-irish-monitor
argirok 4 months ago
parent 8f009f3fee
commit c6dd26dcee

@ -21,9 +21,8 @@ export class UserProfile{
})
export class UserProfileService {
private subscription;
private readonly getUserProfileSubject: AdvancedAsyncSubject<UserProfile> = new AdvancedAsyncSubject<UserProfile>();
private readonly userProfileSubject: AdvancedAsyncSubject<UserProfile> = new AdvancedAsyncSubject<UserProfile>();
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<UserProfile> {
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<UserProfile>(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();
}

Loading…
Cancel
Save