72044476a8
Lazy loaded everything TODO: The cash flow module when clicking on sub-links, it reloads the whole page, it needs to be diagnosed and fixed, this problem also exists in the other modules TODO: Rename folders and modules such as account to accounts to match the url
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
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<Attendance> {
|
|
const getUrl: string = (date === null) ? url : `${url}/${date}`;
|
|
return <Observable<Attendance>>this.http.get<Attendance>(getUrl)
|
|
.pipe(
|
|
catchError(this.log.handleError(serviceName, `get date=${date}`))
|
|
);
|
|
}
|
|
|
|
save(attendance: Attendance): Observable<Attendance> {
|
|
return <Observable<Attendance>>this.http.post<Attendance>(`${url}/${attendance.date}`, attendance, httpOptions)
|
|
.pipe(
|
|
catchError(this.log.handleError(serviceName, 'save'))
|
|
);
|
|
}
|
|
}
|