import {Injectable} from '@angular/core'; import {Observable} from 'rxjs/internal/Observable'; import {catchError} from 'rxjs/operators'; import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http'; import {Attendance} from './attendance'; import {ErrorLoggerService} from '../core/error-logger.service'; const httpOptions = { headers: new HttpHeaders({'Content-Type': 'application/json'}) }; const url = '/api/attendance'; const serviceName = 'AttendanceService'; @Injectable({providedIn: 'root'}) export class AttendanceService { constructor(private http: HttpClient, private log: ErrorLoggerService) { } get(date: string): Observable { const getUrl: string = (date === null) ? url : `${url}/${date}`; return >this.http.get(getUrl) .pipe( catchError(this.log.handleError(serviceName, `get date=${date}`)) ); } save(attendance: Attendance): Observable { return >this.http.post(`${url}/${attendance.date}`, attendance, httpOptions) .pipe( catchError(this.log.handleError(serviceName, 'save')) ); } }