Projekt

Obecné

Profil

Stáhnout (907 Bajtů) Statistiky
| Větev: | Tag: | Revize:
1 3fcf8b67 Hung Hoang
import {Injectable} from '@angular/core';
2 9c7b1b63 Václav Jirák
import {UserService} from './user.service';
3
import {Observable} from 'rxjs';
4 fd5ab42e Hung Hoang
import {UserProfile} from '../../models/user.model';
5 9c7b1b63 Václav Jirák
6
@Injectable({
7
  providedIn: 'root'
8
})
9
export class ProfileService {
10
  private profile: UserProfile;
11
12
  constructor(
13
    private userService: UserService
14
  ) {
15 f8b40fd5 Hung Hoang
    // userService.getUserProfile(1)
16 18dbad83 Václav Jirák
    //   .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 f8b40fd5 Hung Hoang
        this.userService.getUserProfile(1) // TODO zmenit id na prihlaseneho uzivatele
26 9c7b1b63 Václav Jirák
          .subscribe((data: UserProfile) => {
27
            this.profile = data;
28
            observer.next(this.profile);
29
            observer.complete();
30
          });
31
      }
32
    });
33
  }
34
35
}