46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
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<MenuEngineeringReport> {
|
|
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<MenuEngineeringReport>(url, options)
|
|
.pipe(catchError(this.log.handleError(serviceName, 'get'))) as Observable<MenuEngineeringReport>;
|
|
}
|
|
|
|
print(startDate: string | null, finishDate: string | null): Observable<boolean> {
|
|
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<boolean>(printUrl, options)
|
|
.pipe(catchError(this.log.handleError(serviceName, 'print'))) as Observable<boolean>;
|
|
}
|
|
}
|