56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { catchError } from 'rxjs/operators';
|
|
import { Observable } from 'rxjs/internal/Observable';
|
|
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
|
import { CashierCheckout } from './cashier-checkout';
|
|
import { ErrorLoggerService } from '../core/error-logger.service';
|
|
import { User } from '../core/user';
|
|
|
|
const httpOptions = {
|
|
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
|
};
|
|
|
|
const url = '/v1/checkout';
|
|
const urlActiveCashiers = '/v1/active-cashiers';
|
|
const serviceName = 'CashierCheckoutService';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class CashierCheckoutService {
|
|
|
|
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
|
}
|
|
|
|
list(id: string, startDate: string, finishDate): Observable<CashierCheckout> {
|
|
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 <Observable<CashierCheckout>>this.http.get<CashierCheckout>(listUrl, options)
|
|
.pipe(
|
|
catchError(this.log.handleError(serviceName, 'list'))
|
|
);
|
|
}
|
|
|
|
activeCashiers(startDate: string, finishDate): 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 <Observable<User[]>>this.http.get<User[]>(urlActiveCashiers, options)
|
|
|
|
.pipe(
|
|
catchError(this.log.handleError(serviceName, 'activeCashiers'))
|
|
);
|
|
}
|
|
|
|
}
|