44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import { HttpClient, HttpParams } from '@angular/common/http';
|
|
import { Injectable } from '@angular/core';
|
|
import { Observable } from 'rxjs/internal/Observable';
|
|
import { catchError } from 'rxjs/operators';
|
|
|
|
import { ErrorLoggerService } from '../core/error-logger.service';
|
|
|
|
import { CashFlow } from './cash-flow';
|
|
|
|
const url = '/api/cash-flow';
|
|
const serviceName = 'CashFlowService';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class CashFlowService {
|
|
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
|
|
|
list(
|
|
id: string | null,
|
|
startDate: string | null,
|
|
finishDate: string | null,
|
|
): Observable<CashFlow> {
|
|
const options = { params: new HttpParams() };
|
|
if (startDate !== null) {
|
|
options.params = options.params.set('s', startDate);
|
|
}
|
|
if (finishDate !== null) {
|
|
options.params = options.params.set('f', finishDate);
|
|
}
|
|
let listUrl = '';
|
|
if (id !== null) {
|
|
listUrl = `${url}/${id}`;
|
|
} else if (startDate || finishDate) {
|
|
listUrl = `${url}/data`;
|
|
} else {
|
|
listUrl = url;
|
|
}
|
|
return this.http
|
|
.get<CashFlow>(listUrl, options)
|
|
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<CashFlow>;
|
|
}
|
|
}
|