Files
barker/bookie/src/app/cashier-report/cashier-report.service.ts

66 lines
2.2 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 { 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<CashierReport> {
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<CashierReport>(listUrl, options)
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<CashierReport>;
}
activeCashiers(startDate: string | null, finishDate: string | null): Observable<User[]> {
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<User[]>(`${url}/active`, options)
.pipe(catchError(this.log.handleError(serviceName, 'activeCashiers'))) as Observable<User[]>;
}
print(id: string, startDate: string | null, finishDate: string | null): Observable<boolean> {
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<boolean>(printUrl, options)
.pipe(catchError(this.log.handleError(serviceName, 'print'))) as Observable<boolean>;
}
}