Fix: FormArrays were not getting cleared and were basically fucking the whole thing up.
Fix: EmployeeAttendance was borking because the inital employee was null.
This commit is contained in:
@@ -79,8 +79,8 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit {
|
||||
this.attendanceTypes = data.attendanceTypes;
|
||||
this.form.controls.startDate.setValue(moment(this.info.startDate, 'DD-MMM-YYYY').toDate());
|
||||
this.form.controls.finishDate.setValue(moment(this.info.finishDate, 'DD-MMM-YYYY').toDate());
|
||||
this.form.controls.employee.setValue(this.info.employee.name);
|
||||
this.form.controls.attendances.reset();
|
||||
this.form.controls.employee.setValue(this.info.employee?.name ?? '');
|
||||
this.form.controls.attendances.clear();
|
||||
this.info.body.forEach((x) =>
|
||||
this.form.controls.attendances.push(
|
||||
new FormGroup({
|
||||
@@ -120,12 +120,14 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit {
|
||||
const formValue = this.form.value;
|
||||
this.info.startDate = moment(formValue.startDate).format('DD-MMM-YYYY');
|
||||
this.info.finishDate = moment(formValue.finishDate).format('DD-MMM-YYYY');
|
||||
this.router.navigate(['/employee-attendance', this.info.employee.id], {
|
||||
queryParams: {
|
||||
startDate: this.info.startDate,
|
||||
finishDate: this.info.finishDate,
|
||||
},
|
||||
});
|
||||
if (this.info.employee) {
|
||||
this.router.navigate(['/employee-attendance', this.info.employee.id], {
|
||||
queryParams: {
|
||||
startDate: this.info.startDate,
|
||||
finishDate: this.info.finishDate,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
save() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
|
||||
import { ErrorLoggerService } from '../core/error-logger.service';
|
||||
@@ -35,6 +35,9 @@ export class EmployeeAttendanceService {
|
||||
}
|
||||
|
||||
save(employeeAttendance: EmployeeAttendance): Observable<EmployeeAttendance> {
|
||||
if (!employeeAttendance.employee) {
|
||||
return observableOf(new EmployeeAttendance());
|
||||
}
|
||||
const { id } = employeeAttendance.employee;
|
||||
return this.http
|
||||
.post<EmployeeAttendance>(`${url}/${id}`, employeeAttendance)
|
||||
|
||||
@@ -5,13 +5,12 @@ import { EmployeeAttendanceItem } from './employee-attendance-item';
|
||||
export class EmployeeAttendance {
|
||||
startDate: string;
|
||||
finishDate: string;
|
||||
employee: Employee;
|
||||
employee?: Employee;
|
||||
body: EmployeeAttendanceItem[];
|
||||
|
||||
public constructor(init?: Partial<EmployeeAttendance>) {
|
||||
this.startDate = '';
|
||||
this.finishDate = '';
|
||||
this.employee = new Employee();
|
||||
this.body = [];
|
||||
Object.assign(this, init);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user