32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import { HttpClient } from '@angular/common/http';
|
|
import { Injectable } from '@angular/core';
|
|
import { Observable } from 'rxjs/internal/Observable';
|
|
import { catchError } from 'rxjs/operators';
|
|
|
|
import { ErrorLoggerService } from '../core/error-logger.service';
|
|
|
|
import { Attendance } from './attendance';
|
|
|
|
const url = '/api/attendance';
|
|
const serviceName = 'AttendanceService';
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class AttendanceService {
|
|
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
|
|
|
get(date: string | null): Observable<Attendance> {
|
|
const getUrl: string = date === null ? url : `${url}/${date}`;
|
|
return this.http
|
|
.get<Attendance>(getUrl)
|
|
.pipe(
|
|
catchError(this.log.handleError(serviceName, `get date=${date}`)),
|
|
) as Observable<Attendance>;
|
|
}
|
|
|
|
save(attendance: Attendance): Observable<Attendance> {
|
|
return this.http
|
|
.post<Attendance>(`${url}/${attendance.date}`, attendance)
|
|
.pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable<Attendance>;
|
|
}
|
|
}
|