1 import { Observable, ReplaySubject } from 'rxjs'
2 import { catchError, map, tap } from 'rxjs/operators'
3 import { HttpClient } from '@angular/common/http'
4 import { Injectable } from '@angular/core'
5 import { RestExtractor } from '@app/core'
6 import { Account as ServerAccount } from '@shared/models'
7 import { environment } from '../../../../environments/environment'
8 import { Account } from './account.model'
11 export class AccountService {
12 static BASE_ACCOUNT_URL = environment.apiUrl + '/api/v1/accounts/'
14 accountLoaded = new ReplaySubject<Account>(1)
17 private authHttp: HttpClient,
18 private restExtractor: RestExtractor
21 getAccount (id: number | string): Observable<Account> {
22 return this.authHttp.get<ServerAccount>(AccountService.BASE_ACCOUNT_URL + id)
24 map(accountHash => new Account(accountHash)),
25 tap(account => this.accountLoaded.next(account)),
26 catchError(res => this.restExtractor.handleError(res))