1 import { Injectable } from '@angular/core';
3 import { AuthHttp, RestExtractor, ResultList, User } from '../../../shared';
6 export class UserService {
7 // TODO: merge this constant with account
8 private static BASE_USERS_URL = '/api/v1/users/';
11 private authHttp: AuthHttp,
12 private restExtractor: RestExtractor
15 addUser(username: string, password: string) {
21 return this.authHttp.post(UserService.BASE_USERS_URL, body)
22 .map(this.restExtractor.extractDataBool)
23 .catch((res) => this.restExtractor.handleError(res));
27 return this.authHttp.get(UserService.BASE_USERS_URL)
28 .map(this.restExtractor.extractDataList)
29 .map(this.extractUsers)
30 .catch((res) => this.restExtractor.handleError(res));
33 removeUser(user: User) {
34 return this.authHttp.delete(UserService.BASE_USERS_URL + user.id);
37 private extractUsers(result: ResultList) {
38 const usersJson = result.data;
39 const totalUsers = result.total;
41 for (const userJson of usersJson) {
42 users.push(new User(userJson));
45 return { users, totalUsers };