Fix: Product ledger was not totalling. This is because for some reason, pydantic was sending the data as string when the field was nullable
44 lines
1.6 KiB
TypeScript
44 lines
1.6 KiB
TypeScript
import { HttpClient, HttpParams } from '@angular/common/http';
|
|
import { Injectable } from '@angular/core';
|
|
import { Observable, of as observableOf } from 'rxjs';
|
|
import { catchError } from 'rxjs/operators';
|
|
|
|
import { ErrorLoggerService } from '../core/error-logger.service';
|
|
|
|
import { EmployeeAttendance } from './employee-attendance';
|
|
|
|
const url = '/api/employee-attendance';
|
|
const serviceName = 'EmployeeAttendanceService';
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class EmployeeAttendanceService {
|
|
constructor(
|
|
private http: HttpClient,
|
|
private log: ErrorLoggerService,
|
|
) {}
|
|
|
|
get(id: string | null, startDate: string | null, finishDate: string | null): Observable<EmployeeAttendance> {
|
|
const getUrl: string = id === null ? url : `${url}/${id}`;
|
|
const options = { params: new HttpParams() };
|
|
if (startDate !== null) {
|
|
options.params = options.params.set('s', startDate);
|
|
}
|
|
if (finishDate !== null) {
|
|
options.params = options.params.set('f', finishDate);
|
|
}
|
|
return this.http
|
|
.get<EmployeeAttendance>(getUrl, options)
|
|
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) as Observable<EmployeeAttendance>;
|
|
}
|
|
|
|
save(employeeAttendance: EmployeeAttendance): Observable<EmployeeAttendance> {
|
|
if (!employeeAttendance.employee) {
|
|
return observableOf(new EmployeeAttendance());
|
|
}
|
|
const { id } = employeeAttendance.employee;
|
|
return this.http
|
|
.post<EmployeeAttendance>(`${url}/${id}`, employeeAttendance)
|
|
.pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable<EmployeeAttendance>;
|
|
}
|
|
}
|