Migrate to HttpClient in Operation module.

This commit is contained in:
Alexis Lahouze
2017-07-31 12:50:59 +02:00
parent 849a7ae95c
commit c9e1483206
3 changed files with 31 additions and 31 deletions

View File

@ -5,14 +5,14 @@ import * as moment from 'moment';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Rx';
import { Restangular } from "ngx-restangular";
import { HttpClient, HttpParams } from "@angular/common/http";
import { Category } from './category';
@Injectable()
export class CategoryService {
constructor(
private restangular: Restangular
private http: HttpClient
) {}
formatDate(date: Date|string) {
@ -24,16 +24,16 @@ export class CategoryService {
}
query(id: number, minDate: Date = null, maxDate: Date = null): Observable<Category[]> {
var dateRange: any = {};
let params: HttpParams = new HttpParams();
if(minDate) {
dateRange.begin = this.formatDate(minDate);
params = params.set('begin', this.formatDate(minDate));
}
if(maxDate) {
dateRange.end = this.formatDate(maxDate);
params = params.set('end', this.formatDate(maxDate));
}
return this.restangular.one('account', id).getList('category', dateRange);
return this.http.get<Category[]>(`/api/account/${id}/category`, { params: params});
}
}