barker/bookie/src/app/settings/settings.service.ts

30 lines
1.1 KiB
TypeScript

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/internal/Observable';
import { catchError, map } from 'rxjs/operators';
import { ErrorLoggerService } from '../core/error-logger.service';
const serviceName = 'SettingsService';
@Injectable({ providedIn: 'root' })
export class SettingsService {
constructor(private http: HttpClient, private log: 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>;
}
}