import { Observable } from "rxjs/Observable" ; import { Injectable } from "@angular/core" ; import { Response } from "@angular/http" ; import { User } from "../domains" ; import { objToSearchParams } from "./helpers" ; import { PageRequest , Page , UserParams } from "../dto" ; import { JsonHttp } from "./" ; const url = '/api/users' ; const defaultPageRequest = { page : 1 , size : 5 } ; @ Injectable ( ) export class UserService { constructor ( private http ) { } list ( pageRequest = defaultPageRequest ) { return this . http . get ( url , { search : objToSearchParams ( pageRequest ) } ) . map ( res => res . json ( ) ) ; } get ( id ) { return this . http . get ( `${ url }/${ id }` ) . map ( res => res . json ( ) ) ; } create ( params ) { return this . http . post ( url , params ) ; } updateMe ( userParam ) { return this . http . patch ( `${ url }/me` , userParam ) ; } }