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 { const getUrl: string = date === null ? url : `${url}/${date}`; return this.http .get(getUrl) .pipe( catchError(this.log.handleError(serviceName, `get date=${date}`)), ) as Observable; } save(attendance: Attendance): Observable { return this.http .post(`${url}/${attendance.date}`, attendance) .pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable; } }