1 |
9c7b1b63
|
Václav Jirák
|
import { Injectable } from '@angular/core';
|
2 |
|
|
import {UserProfile} from '../models/user-profile.model';
|
3 |
|
|
import {UserService} from './user.service';
|
4 |
|
|
import {Observable} from 'rxjs';
|
5 |
|
|
|
6 |
|
|
@Injectable({
|
7 |
|
|
providedIn: 'root'
|
8 |
|
|
})
|
9 |
|
|
export class ProfileService {
|
10 |
|
|
private profile: UserProfile;
|
11 |
|
|
|
12 |
|
|
constructor(
|
13 |
|
|
private userService: UserService
|
14 |
|
|
) {
|
15 |
18dbad83
|
Václav Jirák
|
// userService.getEmployeeProfile(1)
|
16 |
|
|
// .subscribe((data: UserProfile) => this.profile = data);
|
17 |
9c7b1b63
|
Václav Jirák
|
}
|
18 |
|
|
|
19 |
|
|
getProfile(): Observable<UserProfile> {
|
20 |
|
|
return new Observable((observer) => {
|
21 |
|
|
if (this.profile) {
|
22 |
|
|
observer.next(this.profile);
|
23 |
|
|
observer.complete();
|
24 |
|
|
} else {
|
25 |
|
|
this.userService.getEmployeeProfile(1) // TODO zmenit id na prihlaseneho uzivatele
|
26 |
|
|
.subscribe((data: UserProfile) => {
|
27 |
|
|
this.profile = data;
|
28 |
|
|
observer.next(this.profile);
|
29 |
|
|
observer.complete();
|
30 |
|
|
});
|
31 |
|
|
}
|
32 |
|
|
});
|
33 |
|
|
}
|
34 |
|
|
|
35 |
|
|
}
|