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 { User } from '../core/user'; import { CashierReport } from './cashier-report'; const url = '/api/cashier-report'; const serviceName = 'CashierReportService'; @Injectable({ providedIn: 'root', }) export class CashierReportService { constructor(private http: HttpClient, private log: ErrorLoggerService) {} list( id: string | null, startDate: string | null, finishDate: string | null, ): Observable { const listUrl = id === null ? url : `${url}/${id}`; 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(listUrl, options) .pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable; } activeCashiers(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}/active`, options) .pipe(catchError(this.log.handleError(serviceName, 'activeCashiers'))) as Observable; } print(id: string, startDate: string | null, finishDate: string | null): Observable { const printUrl = `${url}/print/${id}`; 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; } }