From c35e9d911195423cc5fabd94d4f65fa48eda11a4 Mon Sep 17 00:00:00 2001 From: Constantin Simonis Date: Thu, 9 Jan 2025 11:48:21 +0100 Subject: [PATCH] actually make it function this time and refactor --- src/app/employee/edit/edit.component.ts | 7 ++++++- src/app/qualification/table/table.component.ts | 12 +++++++++++- src/app/services/employee-api.service.ts | 4 ++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/app/employee/edit/edit.component.ts b/src/app/employee/edit/edit.component.ts index ca61374..535f94d 100644 --- a/src/app/employee/edit/edit.component.ts +++ b/src/app/employee/edit/edit.component.ts @@ -57,7 +57,12 @@ export class EditComponent implements OnInit { return; } - this.employeeService.create(this.employeeForm.value as Employee).subscribe(); + if (this.employee.id === undefined) { + console.error('Employee ID is undefined'); + return; + } + + this.employeeService.update(this.employeeForm.value as Employee, this.employee.id).subscribe(); this.dialogRef.close(); } } diff --git a/src/app/qualification/table/table.component.ts b/src/app/qualification/table/table.component.ts index 86847dd..cfae55b 100644 --- a/src/app/qualification/table/table.component.ts +++ b/src/app/qualification/table/table.component.ts @@ -1,6 +1,7 @@ import {Component, inject, OnInit} from '@angular/core'; import {Observable} from "rxjs"; import {Qualification} from "../Qualification"; +import {AsyncPipe} from "@angular/common"; import {MatDialog} from "@angular/material/dialog"; import QualificationService from "../../services/qualification.service"; import {CreateComponent} from "../create/create.component"; @@ -14,10 +15,18 @@ import { MatColumnDef, MatHeaderCell, MatHeaderCellDef, - MatHeaderRow, MatHeaderRowDef, MatRow, MatRowDef, + MatHeaderRow, + MatHeaderRowDef, + MatRow, + MatRowDef, MatTable } from "@angular/material/table"; +import QualificationService from "../../services/qualification.service"; +import {MatDialog} from "@angular/material/dialog"; +import {CreateComponent} from "../create/create.component"; import {MatIcon} from "@angular/material/icon"; +import {MatButton, MatIconButton} from "@angular/material/button"; +import {EditComponent} from "../edit/edit.component"; import {MatCard, MatCardContent} from "@angular/material/card"; import {MatTooltip} from "@angular/material/tooltip"; import {MatProgressSpinner} from "@angular/material/progress-spinner"; @@ -45,6 +54,7 @@ import {MatProgressSpinner} from "@angular/material/progress-spinner"; MatProgressSpinner ], templateUrl: './table.component.html', + standalone: true, styleUrl: './table.component.css' }) export class QualificationsComponent implements OnInit { diff --git a/src/app/services/employee-api.service.ts b/src/app/services/employee-api.service.ts index 33fd804..c134dad 100644 --- a/src/app/services/employee-api.service.ts +++ b/src/app/services/employee-api.service.ts @@ -23,4 +23,8 @@ export default class EmployeeApiService { public create(employee: Employee) { return this.http.post(`${EmployeeApiService.BASE_URL}/employees`, employee) } + + public update(employee: Employee, id: number) { + return this.http.patch(`${EmployeeApiService.BASE_URL}/employees/${id}`, employee) + } }