brewman/overlord/src/app/profit-loss/profit-loss.service.ts

38 lines
1.1 KiB
TypeScript
Raw Normal View History

import {Injectable} from '@angular/core';
import {catchError} from 'rxjs/operators';
import {Observable} from 'rxjs/internal/Observable';
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
import {ProfitLoss} from './profit-loss';
import {ErrorLoggerService} from '../core/error-logger.service';
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
};
const url = '/api/profit-loss';
const serviceName = 'ProfitLossService';
@Injectable({
providedIn: 'root'
})
export class ProfitLossService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {
}
list(startDate: string, finishDate): Observable<ProfitLoss> {
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);
}
return <Observable<ProfitLoss>>this.http.get<ProfitLoss>(url, options)
.pipe(
catchError(this.log.handleError(serviceName, 'list'))
);
}
}