actually make it function this time and refactor

This commit is contained in:
Constantin Simonis 2025-01-09 11:48:21 +01:00
parent 710ce96764
commit 9acdc6bfc0
Signed by: csimonis
GPG Key ID: 758DD9C506603183
3 changed files with 18 additions and 6 deletions

View File

@ -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();
}
}

View File

@ -1,14 +1,17 @@
import {Component, inject, OnInit} from '@angular/core';
import {Observable} from "rxjs";
import {Qualification} from "../Qualification";
import {AsyncPipe, NgFor} from "@angular/common";
import {AsyncPipe} from "@angular/common";
import {
MatCell, MatCellDef,
MatCell,
MatCellDef,
MatColumnDef,
MatHeaderCell,
MatHeaderCellDef,
MatHeaderRow, MatHeaderRowDef,
MatRow, MatRowDef,
MatHeaderRow,
MatHeaderRowDef,
MatRow,
MatRowDef,
MatTable
} from "@angular/material/table";
import QualificationService from "../../services/qualification.service";
@ -24,7 +27,6 @@ import {MatProgressSpinner} from "@angular/material/progress-spinner";
selector: 'app-qualifications',
imports: [
AsyncPipe,
NgFor,
MatTable,
MatHeaderCell,
MatColumnDef,
@ -43,6 +45,7 @@ import {MatProgressSpinner} from "@angular/material/progress-spinner";
MatProgressSpinner
],
templateUrl: './table.component.html',
standalone: true,
styleUrl: './table.component.css'
})
export class QualificationsComponent implements OnInit{

View File

@ -23,4 +23,8 @@ export default class EmployeeApiService {
public create(employee: Employee) {
return this.http.post<Employee>(`${EmployeeApiService.BASE_URL}/employees`, employee)
}
public update(employee: Employee, id: number) {
return this.http.patch(`${EmployeeApiService.BASE_URL}/employees/${id}`, employee)
}
}