40 lines
915 B
TypeScript
40 lines
915 B
TypeScript
// 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';
|
|
|
|
import { HttpClient, HttpParams } from "@angular/common/http";
|
|
|
|
import { Category } from './category';
|
|
|
|
@Injectable()
|
|
export class CategoryService {
|
|
constructor(
|
|
private http: HttpClient
|
|
) {}
|
|
|
|
formatDate(date: Date|string) {
|
|
if(date instanceof Date) {
|
|
return moment(date).format('YYYY-MM-DD');
|
|
}
|
|
|
|
return date;
|
|
}
|
|
|
|
query(id: number, minDate: Date|string = null, maxDate: Date|string = null): Observable<Category[]> {
|
|
let params: HttpParams = new HttpParams();
|
|
|
|
if(minDate) {
|
|
params = params.set('begin', this.formatDate(minDate));
|
|
}
|
|
|
|
if(maxDate) {
|
|
params = params.set('end', this.formatDate(maxDate));
|
|
}
|
|
|
|
return this.http.get<Category[]>(`/api/account/${id}/category`, { params: params});
|
|
}
|
|
}
|