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