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

29 lines
942 B
TypeScript
Raw Normal View History

import { HttpClient } 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 { ProfitLoss } from './profit-loss';
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 startDateWithSlash = startDate ? `/${startDate}` : '';
const finishDateWithSlash = finishDate ? `/${finishDate}` : '';
return <Observable<ProfitLoss>>(
this.http
.get<ProfitLoss>(`${url}${startDateWithSlash}${finishDateWithSlash}`)
.pipe(catchError(this.log.handleError(serviceName, 'list')))
);
}
}