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 { const url = '/api/lock-information'; return this.http .post(url, lockInformation) .pipe(catchError(this.log.handleError('SettingsService', 'setLockInformation'))) as Observable; } deleteLockInformation(id: string): Observable { const url = '/api/lock-information'; return this.http .delete(`${url}/${id}`) .pipe(catchError(this.log.handleError('SettingsService', 'deleteLockInformation'))) as Observable; } rebaseDatabase(date: string): Observable> { const url = '/api/rebase'; return this.http .post>(`${url}/${date}`, {}) .pipe(catchError(this.log.handleError('SettingsService', 'rebaseDatabase'))) as Observable>; } 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; }>; } }