43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { HttpClient, HttpParams } 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 { BeerSaleReport } from './beer-sale-report';
|
|
|
|
const url = '/api/beer-sale-report';
|
|
const serviceName = 'BeerSaleReportService';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class BeerSaleReportService {
|
|
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
|
|
|
get(
|
|
startDate: string | null,
|
|
finishDate: string | null,
|
|
regular: boolean,
|
|
happy: boolean,
|
|
staff: boolean,
|
|
nc: boolean,
|
|
): Observable<BeerSaleReport> {
|
|
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);
|
|
}
|
|
options.params = options.params.set('r', regular);
|
|
options.params = options.params.set('h', happy);
|
|
options.params = options.params.set('st', staff);
|
|
options.params = options.params.set('n', nc);
|
|
return this.http
|
|
.get<BeerSaleReport>(url, options)
|
|
.pipe(catchError(this.log.handleError(serviceName, 'get'))) as Observable<BeerSaleReport>;
|
|
}
|
|
}
|