Files
brewman/overlord/src/app/settings/settings.service.ts
T

64 lines
2.3 KiB
TypeScript

import { HttpClient, httpResource } from '@angular/common/http';
import { inject, Injectable } from '@angular/core';
import { Observable } from 'rxjs/internal/Observable';
import { catchError } from 'rxjs/operators';
import { ErrorLoggerService } from '../core/error-logger.service';
import { LockInfo } from './lock-info';
@Injectable({ providedIn: 'root' })
export class SettingsService {
private http = inject(HttpClient);
private log = inject(ErrorLoggerService);
getLockInformation() {
const url = '/api/lock-information';
return httpResource<[LockInfo]>(() => url);
}
setLockInformation(lockInformation: LockInfo): Observable<LockInfo[]> {
const url = '/api/lock-information';
return this.http
.post<LockInfo[]>(url, lockInformation)
.pipe(catchError(this.log.handleError('SettingsService', 'setLockInformation'))) as Observable<LockInfo[]>;
}
deleteLockInformation(id: string): Observable<LockInfo[]> {
const url = '/api/lock-information';
return this.http
.delete<LockInfo[]>(`${url}/${id}`)
.pipe(catchError(this.log.handleError('SettingsService', 'deleteLockInformation'))) as Observable<LockInfo[]>;
}
rebaseDatabase(date: string): Observable<Record<string, never>> {
const url = '/api/rebase';
return this.http
.post<Record<string, never>>(`${url}/${date}`, {})
.pipe(catchError(this.log.handleError('SettingsService', 'rebaseDatabase'))) as Observable<Record<string, never>>;
}
setMaintenance(enable: boolean): Observable<{ enabled: boolean; user: string }> {
const url = '/api/maintenance';
return this.http
.post<{ enabled: boolean; user: string }>(url, { enabled: enable })
.pipe(catchError(this.log.handleError('SettingsService', 'setMaintenance'))) as Observable<{
enabled: boolean;
user: string;
}>;
}
getMaintenance() {
const url = '/api/maintenance';
return httpResource<{ enabled: boolean; user: string }>(() => url);
}
checkDatabaseIntegrity(): Observable<{ attendanceCount: number }> {
const url = '/api/db-integrity';
return this.http
.post<{ attendanceCount: number }>(url, {})
.pipe(catchError(this.log.handleError('SettingsService', 'checkDatabaseIntegrity'))) as Observable<{
attendanceCount: number;
}>;
}
}