1 import { Injectable } from '@angular/core'
2 import 'rxjs/add/operator/catch'
3 import 'rxjs/add/operator/map'
4 import { environment } from '../../../environments/environment'
5 import { Observable } from 'rxjs/Observable'
6 import { Account } from '@app/shared/account/account.model'
7 import { RestExtractor } from '@app/shared/rest/rest-extractor.service'
8 import { RestService } from '@app/shared/rest/rest.service'
9 import { HttpClient } from '@angular/common/http'
10 import { Account as ServerAccount } from '../../../../../shared/models/actors/account.model'
11 import { ReplaySubject } from 'rxjs/ReplaySubject'
14 export class AccountService {
15 static BASE_ACCOUNT_URL = environment.apiUrl + '/api/v1/accounts/'
17 accountLoaded = new ReplaySubject<Account>(1)
20 private authHttp: HttpClient,
21 private restExtractor: RestExtractor,
22 private restService: RestService
25 getAccount (id: number): Observable<Account> {
26 return this.authHttp.get<ServerAccount>(AccountService.BASE_ACCOUNT_URL + id)
27 .map(accountHash => new Account(accountHash))
28 .do(account => this.accountLoaded.next(account))
29 .catch((res) => this.restExtractor.handleError(res))