From 611962104014082550cfc1b41c4df5723a464c1c Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 15 Jan 2025 20:45:17 +0100 Subject: [PATCH] feat(qualifikation-form): implement submit functionality and navigation --- .../qualifikation-form.component.html | 6 +----- .../qualifikation-form.component.ts | 21 +++++++++++++++++-- .../qualifikaton-bearbeiten-view.component.ts | 2 +- src/app/service/employee.service.ts | 12 ++++++++++- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/app/components/qualifikation-form/qualifikation-form.component.html b/src/app/components/qualifikation-form/qualifikation-form.component.html index cdd67ea..933437f 100644 --- a/src/app/components/qualifikation-form/qualifikation-form.component.html +++ b/src/app/components/qualifikation-form/qualifikation-form.component.html @@ -32,11 +32,7 @@ } - - - - - + diff --git a/src/app/components/qualifikation-form/qualifikation-form.component.ts b/src/app/components/qualifikation-form/qualifikation-form.component.ts index 166d26b..da59dec 100644 --- a/src/app/components/qualifikation-form/qualifikation-form.component.ts +++ b/src/app/components/qualifikation-form/qualifikation-form.component.ts @@ -6,6 +6,7 @@ import { EmployeeService } from '../../service/employee.service'; import { concatMap, every, from, lastValueFrom, Observable, of, switchMap, take, tap } from 'rxjs'; import { EmployeeNameDataDTO, EmployeeResponseDTO } from '../../models/mitarbeiter'; import { AsyncPipe } from '@angular/common'; +import { Router } from '@angular/router'; @Component({ selector: 'app-qualifikation-form', @@ -22,7 +23,7 @@ export class QualifikationFormComponent { public addableEmployees: Array = []; public addedEmployees: Array = []; - constructor(private skillService: SkillService, private employeeService: EmployeeService) { } + constructor(private skillService: SkillService, private employeeService: EmployeeService, private router: Router) { } setUpForm() { this.skillForm = new FormGroup({ @@ -33,7 +34,6 @@ export class QualifikationFormComponent { addEmployee() { - console.log("called"); const employeeId = Number(this.skillForm.get("newEmployee")?.value); const employee = this.addableEmployees.find(emp => emp.id === employeeId); @@ -72,6 +72,23 @@ export class QualifikationFormComponent { } } + submit() { + for (const employee of this.addedEmployees) { + this.employeeService.getEmployeeById(employee.id).subscribe(employeeResponse => { + this.employeeService.addSkillToEmployee(this.skill.id, employeeResponse); + }); + } + + for (const employee of this.addableEmployees) { + this.employeeService.removeSkillFromEmployee(this.skill.id, employee); + } + + this.skill.skill = this.skillForm.get("name")?.value; + this.skillChange.emit(this.skill); + + this.router.navigate(["/qualifikationen"]); + } + ngOnChanges(): void { this.setUpForm(); this.updateEmployeeLists(); diff --git a/src/app/components/qualifikaton-bearbeiten-view/qualifikaton-bearbeiten-view.component.ts b/src/app/components/qualifikaton-bearbeiten-view/qualifikaton-bearbeiten-view.component.ts index 2ad4759..6e569a8 100644 --- a/src/app/components/qualifikaton-bearbeiten-view/qualifikaton-bearbeiten-view.component.ts +++ b/src/app/components/qualifikaton-bearbeiten-view/qualifikaton-bearbeiten-view.component.ts @@ -18,7 +18,7 @@ export class QualifikatonBearbeitenViewComponent { constructor(private skillService: SkillService, private route: ActivatedRoute) {} submitted(skill: QualificationGetDTO) { - + console.log(skill); } ngOnInit(): void { diff --git a/src/app/service/employee.service.ts b/src/app/service/employee.service.ts index 17062f7..caaf5e1 100644 --- a/src/app/service/employee.service.ts +++ b/src/app/service/employee.service.ts @@ -54,10 +54,20 @@ export class EmployeeService { return this.http.get(`${SkillService.BASE_URL}/employees/${id}`); } + removeSkillFromEmployee(skillId: number, employee: EmployeeResponseDTO) { + let employeePut = this.responseDtoToPutDto(employee); + if (employeePut.skillSet.indexOf(skillId) != 1) { + employeePut.skillSet = employeePut.skillSet.filter(skill => skill != skillId); + } + + this.http.put(`${SkillService.BASE_URL}/employees/${employee.id}`, employeePut).subscribe(); + } addSkillToEmployee(skillId: number, employee: EmployeeResponseDTO) { let employeePut = this.responseDtoToPutDto(employee); - employeePut.skillSet.push(skillId); + if (employeePut.skillSet.indexOf(skillId) == -1) { + employeePut.skillSet.push(skillId); + } this.http.put(`${SkillService.BASE_URL}/employees/${employee.id}`, employeePut).subscribe(); }