aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-main/account/account.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/shared-main/account/account.service.ts')
-rw-r--r--client/src/app/shared/shared-main/account/account.service.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-main/account/account.service.ts b/client/src/app/shared/shared-main/account/account.service.ts
new file mode 100644
index 000000000..8f4abf070
--- /dev/null
+++ b/client/src/app/shared/shared-main/account/account.service.ts
@@ -0,0 +1,29 @@
1import { Observable, ReplaySubject } from 'rxjs'
2import { catchError, map, tap } from 'rxjs/operators'
3import { HttpClient } from '@angular/common/http'
4import { Injectable } from '@angular/core'
5import { RestExtractor } from '@app/core'
6import { Account as ServerAccount } from '@shared/models'
7import { environment } from '../../../../environments/environment'
8import { Account } from './account.model'
9
10@Injectable()
11export 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,
18 private restExtractor: RestExtractor
19 ) {}
20
21 getAccount (id: number | string): Observable<Account> {
22 return this.authHttp.get<ServerAccount>(AccountService.BASE_ACCOUNT_URL + id)
23 .pipe(
24 map(accountHash => new Account(accountHash)),
25 tap(account => this.accountLoaded.next(account)),
26 catchError(res => this.restExtractor.handleError(res))
27 )
28 }
29}