Fix date format in category service.

This commit is contained in:
Alexis Lahouze 2017-07-29 17:07:43 +02:00
parent 89fc42c47a
commit 1bd59cbbf8

View File

@ -1,5 +1,7 @@
// vim: set tw=80 ts=2 sw=2 sts=2: // vim: set tw=80 ts=2 sw=2 sts=2:
import * as moment from 'moment';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Rx'; import { Observable } from 'rxjs/Rx';
@ -13,14 +15,23 @@ export class CategoryService {
private restangular: Restangular private restangular: Restangular
) {} ) {}
formatDate(date: Date|string) {
if(date instanceof Date) {
return moment(date).format('YYYY-MM-DD');
}
return date;
}
query(id: number, minDate: Date = null, maxDate: Date = null): Observable<Category[]> { query(id: number, minDate: Date = null, maxDate: Date = null): Observable<Category[]> {
var dateRange: any; var dateRange: any = {};
if(minDate) { if(minDate) {
dateRange.begin = minDate; dateRange.begin = this.formatDate(minDate);
} }
if(maxDate) { if(maxDate) {
dateRange.end = maxDate; dateRange.end = this.formatDate(maxDate);
} }
return this.restangular.one('account', id).getList('category', dateRange); return this.restangular.one('account', id).getList('category', dateRange);