import { HttpClient, HttpParams } from '@angular/common/http'; import { Injectable, inject } from '@angular/core'; import { Observable } from 'rxjs'; import { catchError, map } from 'rxjs/operators'; import { ErrorLoggerService } from '../core/error-logger.service'; const serviceName = 'SettingsService'; @Injectable({ providedIn: 'root' }) export class SettingsService { private http = inject(HttpClient); private log = inject(ErrorLoggerService); getPrefillCustomerDiscount(): Observable { const url = '/api/settings/prefill-customer-discount'; return this.http.get<{ value: boolean }>(url).pipe( map((x) => x.value), catchError(this.log.handleError(serviceName, 'getPrefillCustomerDiscount')), ) as Observable; } setPrefillCustomerDiscount(value: boolean): Observable { const url = '/api/settings/prefill-customer-discount'; return this.http.post<{ value: boolean }>(url, { value: value }).pipe( map((x) => x.value), catchError(this.log.handleError(serviceName, 'setPrefillCustomerDiscount')), ) as Observable; } runMaintenance(startDate: string, finishDate: string, beerFile: File, saleFile: File): Observable { const options = { params: new HttpParams().set('s', startDate).set('f', finishDate) }; const url = '/api/maintenance'; const fd = new FormData(); fd.append('beer_file', beerFile); fd.append('sale_file', saleFile); return this.http .post(url, fd, options) .pipe(catchError(this.log.handleError(serviceName, 'runMaintenance'))) as Observable; } }