aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/account/account.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/account/account.service.ts')
-rw-r--r--client/src/app/shared/account/account.service.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/client/src/app/shared/account/account.service.ts b/client/src/app/shared/account/account.service.ts
new file mode 100644
index 000000000..8c66ae04a
--- /dev/null
+++ b/client/src/app/shared/account/account.service.ts
@@ -0,0 +1,31 @@
1import { Injectable } from '@angular/core'
2import 'rxjs/add/operator/catch'
3import 'rxjs/add/operator/map'
4import { environment } from '../../../environments/environment'
5import { Observable } from 'rxjs/Observable'
6import { Account } from '@app/shared/account/account.model'
7import { RestExtractor } from '@app/shared/rest/rest-extractor.service'
8import { RestService } from '@app/shared/rest/rest.service'
9import { HttpClient } from '@angular/common/http'
10import { Account as ServerAccount } from '../../../../../shared/models/actors/account.model'
11import { ReplaySubject } from 'rxjs/ReplaySubject'
12
13@Injectable()
14export class AccountService {
15 static BASE_ACCOUNT_URL = environment.apiUrl + '/api/v1/accounts/'
16
17 accountLoaded = new ReplaySubject<Account>(1)
18
19 constructor (
20 private authHttp: HttpClient,
21 private restExtractor: RestExtractor,
22 private restService: RestService
23 ) {}
24
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))
30 }
31}