feat(qualifikationsverwaltung): add error handling for delete skill
All checks were successful
Playwright Tests / test (pull_request) Successful in 2m12s

This commit is contained in:
Jan Gleytenhoover 2025-01-22 09:26:46 +01:00
parent 2a337f3586
commit 5f18aa207d
Signed by: jank
GPG key ID: 50620ADD22CD330B
2 changed files with 29 additions and 11 deletions

View file

@ -12,7 +12,8 @@
<h1>Qualifications</h1> <h1>Qualifications</h1>
</div> </div>
<div class="header-actions"> <div class="d-flex flex-column">
<div class="row header-actions">
<form [formGroup]="searchForm"> <form [formGroup]="searchForm">
<div class="search-bar"> <div class="search-bar">
<input type="text" placeholder="Search employee" formControlName="search"> <input type="text" placeholder="Search employee" formControlName="search">
@ -20,7 +21,16 @@
</div> </div>
<p class="text-body-tertiary">Search for a propertiy of a Qualification. eg. Name</p> <p class="text-body-tertiary">Search for a propertiy of a Qualification. eg. Name</p>
</form> </form>
<button (click)="createSkill()" class="add-button">Add qualification</button> <div class="d-flex">
<button (click)="createSkill()" class="add-button me-auto">Add qualification</button>
</div>
</div>
@if (errorDeletingSkill) {
<div class="row">
<p class="alert alert-danger">This Qualification can not be deleted because it still has employees.</p>
</div>
}
</div> </div>
<table class="employee-table"> <table class="employee-table">

View file

@ -14,6 +14,7 @@ import { Router } from '@angular/router';
export class QualifikationsverwaltungComponent { export class QualifikationsverwaltungComponent {
skills: Array<QualificationGetDTO> = []; skills: Array<QualificationGetDTO> = [];
public searchForm!: FormGroup; public searchForm!: FormGroup;
public errorDeletingSkill = false;
constructor(private skillService: SkillService, private router: Router) { } constructor(private skillService: SkillService, private router: Router) { }
@ -44,8 +45,15 @@ export class QualifikationsverwaltungComponent {
} }
deleteSkill(id: number) { deleteSkill(id: number) {
this.skillService.getEmployeesBySkill(id).subscribe(employees => {
this.errorDeletingSkill = false;
if (employees.employees.length == 0) {
this.skillService.deleteSkill(id); this.skillService.deleteSkill(id);
this.skills = this.skills.filter(skill => skill.id != id); this.skills = this.skills.filter(skill => skill.id != id);
} else {
this.errorDeletingSkill = true;
}
});
} }
ngOnInit(): void { ngOnInit(): void {