diff options
Diffstat (limited to 'client/src/app/+admin/users/shared/user.service.ts')
-rw-r--r-- | client/src/app/+admin/users/shared/user.service.ts | 20 |
1 files changed, 3 insertions, 17 deletions
diff --git a/client/src/app/+admin/users/shared/user.service.ts b/client/src/app/+admin/users/shared/user.service.ts index d9005b213..f6d360e09 100644 --- a/client/src/app/+admin/users/shared/user.service.ts +++ b/client/src/app/+admin/users/shared/user.service.ts | |||
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; | |||
2 | import 'rxjs/add/operator/catch'; | 2 | import 'rxjs/add/operator/catch'; |
3 | import 'rxjs/add/operator/map'; | 3 | import 'rxjs/add/operator/map'; |
4 | 4 | ||
5 | import { AuthHttp, RestExtractor, ResultList, User } from '../../../shared'; | 5 | import { AuthHttp, RestExtractor, RestDataSource, User } from '../../../shared'; |
6 | 6 | ||
7 | @Injectable() | 7 | @Injectable() |
8 | export class UserService { | 8 | export class UserService { |
@@ -25,25 +25,11 @@ export class UserService { | |||
25 | .catch(this.restExtractor.handleError); | 25 | .catch(this.restExtractor.handleError); |
26 | } | 26 | } |
27 | 27 | ||
28 | getUsers() { | 28 | getDataSource() { |
29 | return this.authHttp.get(UserService.BASE_USERS_URL) | 29 | return new RestDataSource(this.authHttp, UserService.BASE_USERS_URL); |
30 | .map(this.restExtractor.extractDataList) | ||
31 | .map(this.extractUsers) | ||
32 | .catch((res) => this.restExtractor.handleError(res)); | ||
33 | } | 30 | } |
34 | 31 | ||
35 | removeUser(user: User) { | 32 | removeUser(user: User) { |
36 | return this.authHttp.delete(UserService.BASE_USERS_URL + user.id); | 33 | return this.authHttp.delete(UserService.BASE_USERS_URL + user.id); |
37 | } | 34 | } |
38 | |||
39 | private extractUsers(result: ResultList) { | ||
40 | const usersJson = result.data; | ||
41 | const totalUsers = result.total; | ||
42 | const users = []; | ||
43 | for (const userJson of usersJson) { | ||
44 | users.push(new User(userJson)); | ||
45 | } | ||
46 | |||
47 | return { users, totalUsers }; | ||
48 | } | ||
49 | } | 35 | } |