import { HttpClient, HttpParams } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { catchError } from 'rxjs/operators'; import { ErrorLoggerService } from '../core/error-logger.service'; import { MenuEngineeringReport } from './menu-engineering-report'; const url = '/api/menu-engineering-report'; const serviceName = 'MenuEngineeringReportService'; @Injectable({ providedIn: 'root', }) export class MenuEngineeringReportService { constructor(private http: HttpClient, private log: ErrorLoggerService) {} get(startDate: string | null, finishDate: string | null): Observable { 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 this.http .get(url, options) .pipe(catchError(this.log.handleError(serviceName, 'get'))) as Observable; } print(startDate: string | null, finishDate: string | null): Observable { const printUrl = `${url}/print`; 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 this.http .get(printUrl, options) .pipe(catchError(this.log.handleError(serviceName, 'print'))) as Observable; } }