Files
barker/bookie/src/app/settings/settings.service.ts
Amritanshu 44513dd6be Moved to Angular 20
Moved to Tailwind 4
Moved to Python 3.13
Enabled arm64/v8 Builds
2025-07-02 04:32:35 +00:00

42 lines
1.6 KiB
TypeScript

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<boolean> {
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<boolean>;
}
setPrefillCustomerDiscount(value: boolean): Observable<boolean> {
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<boolean>;
}
runMaintenance(startDate: string, finishDate: string, beerFile: File, saleFile: File): Observable<boolean> {
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<boolean>(url, fd, options)
.pipe(catchError(this.log.handleError(serviceName, 'runMaintenance'))) as Observable<boolean>;
}
}