From 4c921bfaaa5c8fee545f7778b6defbde2061b18d Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Sat, 29 Jul 2017 17:57:50 +0200 Subject: [PATCH] Add minDate and maxDate parameters in Operation query. --- src/operations/operation.service.ts | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) 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 {