]>
Commit | Line | Data |
---|---|---|
db400f44 | 1 | import { map, tap, catchError } from 'rxjs/operators' |
0626e7af | 2 | import { Injectable } from '@angular/core' |
0626e7af | 3 | import { environment } from '../../../environments/environment' |
db400f44 | 4 | import { Observable, ReplaySubject } from 'rxjs' |
0626e7af C |
5 | import { Account } from '@app/shared/account/account.model' |
6 | import { RestExtractor } from '@app/shared/rest/rest-extractor.service' | |
0626e7af C |
7 | import { HttpClient } from '@angular/common/http' |
8 | import { Account as ServerAccount } from '../../../../../shared/models/actors/account.model' | |
0626e7af C |
9 | |
10 | @Injectable() | |
11 | export class AccountService { | |
12 | static BASE_ACCOUNT_URL = environment.apiUrl + '/api/v1/accounts/' | |
13 | ||
14 | accountLoaded = new ReplaySubject<Account>(1) | |
15 | ||
16 | constructor ( | |
17 | private authHttp: HttpClient, | |
db400f44 | 18 | private restExtractor: RestExtractor |
0626e7af C |
19 | ) {} |
20 | ||
d14a9532 | 21 | getAccount (id: number | string): Observable<Account> { |
0626e7af | 22 | return this.authHttp.get<ServerAccount>(AccountService.BASE_ACCOUNT_URL + id) |
db400f44 C |
23 | .pipe( |
24 | map(accountHash => new Account(accountHash)), | |
25 | tap(account => this.accountLoaded.next(account)), | |
26 | catchError(res => this.restExtractor.handleError(res)) | |
27 | ) | |
0626e7af C |
28 | } |
29 | } |