diff --git a/src/operations/operation.service.ts b/src/operations/operation.service.ts index 0a211fb..d83b67b 100644 --- a/src/operations/operation.service.ts +++ b/src/operations/operation.service.ts @@ -1,5 +1,7 @@ // vim: set tw=80 ts=2 sw=2 sts=2 : +import * as moment from 'moment'; + import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Rx'; @@ -21,8 +23,30 @@ export class OperationService { return this.restangular.one('operation', id); } - query(): Observable { - return this.all().getList(); + formatDate(date: Date|string) { + if(date instanceof Date) { + return moment(date).format('YYYY-MM-DD'); + } + + return date; + } + + query( + accountId: number, + minDate: Date|string = null, + maxDate: Date|string = null + ): Observable { + var dateRange: any = {}; + + if(minDate) { + dateRange.begin = this.formatDate(minDate); + } + + if(maxDate) { + dateRange.end = this.formatDate(maxDate); + } + + return this.all().getList([], dateRange); } get(id: number): Observable {