backend without errors

This commit is contained in:
2025-10-11 19:56:43 +02:00
parent 738b7f645a
commit 85dca0ba41
11 changed files with 212 additions and 344 deletions

View File

@@ -1,5 +1,5 @@
// frontend/src/services/employeeService.ts
import { Employee, CreateEmployeeRequest, UpdateEmployeeRequest, Availability } from '../types/employee';
import { Employee, CreateEmployeeRequest, UpdateEmployeeRequest, EmployeeAvailability } from '../../../backend/src/models/employee';
const API_BASE_URL = 'http://localhost:3002/api';
@@ -90,7 +90,7 @@ export class EmployeeService {
}
}
async getAvailabilities(employeeId: string): Promise<Availability[]> {
async getAvailabilities(employeeId: string): Promise<EmployeeAvailability[]> {
const response = await fetch(`${API_BASE_URL}/employees/${employeeId}/availabilities`, {
headers: getAuthHeaders(),
});
@@ -102,7 +102,7 @@ export class EmployeeService {
return response.json();
}
async updateAvailabilities(employeeId: string, availabilities: Availability[]): Promise<Availability[]> {
async updateAvailabilities(employeeId: string, availabilities: EmployeeAvailability[]): Promise<EmployeeAvailability[]> {
const response = await fetch(`${API_BASE_URL}/employees/${employeeId}/availabilities`, {
method: 'PUT',
headers: getAuthHeaders(),

View File

@@ -1,6 +1,6 @@
// frontend/src/services/shiftPlanService.ts
import { authService } from './authService';
import { ShiftPlan, CreateShiftPlanRequest, ShiftSlot } from '../types/shiftPlan.js';
import { ShiftPlan, CreateShiftPlanRequest, Shift } from '../../../backend/src/models/shiftPlan.js';
const API_BASE = 'http://localhost:3002/api/shift-plans';
@@ -21,20 +21,7 @@ export const shiftPlanService = {
throw new Error('Fehler beim Laden der Schichtpläne');
}
const data = await response.json();
// Convert snake_case to camelCase
return data.map((plan: any) => ({
id: plan.id,
name: plan.name,
startDate: plan.start_date, // Convert here
endDate: plan.end_date, // Convert here
templateId: plan.template_id,
status: plan.status,
createdBy: plan.created_by,
createdAt: plan.created_at,
shifts: plan.shifts || []
}));
return await response.json();
},
async getShiftPlan(id: string): Promise<ShiftPlan> {
@@ -53,20 +40,7 @@ export const shiftPlanService = {
throw new Error('Schichtplan nicht gefunden');
}
const data = await response.json();
// Convert snake_case to camelCase
return data.map((plan: any) => ({
id: plan.id,
name: plan.name,
startDate: plan.start_date,
endDate: plan.end_date,
templateId: plan.template_id,
status: plan.status,
createdBy: plan.created_by,
createdAt: plan.created_at,
shifts: plan.shifts || []
}));
return await response.json();
},
async createShiftPlan(plan: CreateShiftPlanRequest): Promise<ShiftPlan> {
@@ -127,60 +101,5 @@ export const shiftPlanService = {
}
throw new Error('Fehler beim Löschen des Schichtplans');
}
},
async updateShiftPlanShift(planId: string, shift: ShiftSlot): Promise<void> {
const response = await fetch(`${API_BASE}/${planId}/shifts/${shift.id}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
...authService.getAuthHeaders()
},
body: JSON.stringify(shift)
});
if (!response.ok) {
if (response.status === 401) {
authService.logout();
throw new Error('Nicht authorisiert - bitte erneut anmelden');
}
throw new Error('Fehler beim Aktualisieren der Schicht');
}
},
async addShiftPlanShift(planId: string, shift: Omit<ShiftSlot, 'id' | 'shiftPlanId' | 'assignedEmployees'>): Promise<void> {
const response = await fetch(`${API_BASE}/${planId}/shifts`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...authService.getAuthHeaders()
},
body: JSON.stringify(shift)
});
if (!response.ok) {
if (response.status === 401) {
authService.logout();
throw new Error('Nicht authorisiert - bitte erneut anmelden');
}
throw new Error('Fehler beim Hinzufügen der Schicht');
}
},
async deleteShiftPlanShift(planId: string, shiftId: string): Promise<void> {
const response = await fetch(`${API_BASE}/${planId}/shifts/${shiftId}`, {
method: 'DELETE',
headers: {
...authService.getAuthHeaders()
}
});
if (!response.ok) {
if (response.status === 401) {
authService.logout();
throw new Error('Nicht authorisiert - bitte erneut anmelden');
}
throw new Error('Fehler beim Löschen der Schicht');
}
}
};
};

View File

@@ -1,5 +1,5 @@
// frontend/src/services/shiftTemplateService.ts
import { ShiftPlan } from '../../../backend/src/models/shiftTemplate.js';
import { ShiftPlan } from '../../../backend/src/models/shiftPlan.js';
import { authService } from './authService';
const API_BASE = 'http://localhost:3002/api/shift-templates';
@@ -22,15 +22,10 @@ export const shiftTemplateService = {
}
const templates = await response.json();
// Sortiere die Vorlagen so, dass die Standard-Vorlage immer zuerst kommt
return templates.sort((a: TemplateShift, b: TemplateShift) => {
if (a.isDefault && !b.isDefault) return -1;
if (!a.isDefault && b.isDefault) return 1;
return new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime();
});
return templates;
},
async getTemplate(id: string): Promise<TemplateShift> {
async getTemplate(id: string): Promise<ShiftPlan> {
const response = await fetch(`${API_BASE}/${id}`, {
headers: {
'Content-Type': 'application/json',
@@ -49,18 +44,7 @@ export const shiftTemplateService = {
return response.json();
},
async createTemplate(template: Omit<TemplateShift, 'id' | 'createdAt' | 'createdBy'>): Promise<TemplateShift> {
// Wenn diese Vorlage als Standard markiert ist,
// fragen wir den Benutzer, ob er wirklich die Standard-Vorlage ändern möchte
if (template.isDefault) {
const confirm = window.confirm(
'Diese Vorlage wird als neue Standard-Vorlage festgelegt. Die bisherige Standard-Vorlage wird dadurch zu einer normalen Vorlage. Möchten Sie fortfahren?'
);
if (!confirm) {
throw new Error('Operation abgebrochen');
}
}
async createTemplate(template: Omit<ShiftPlan, 'id' | 'createdAt' | 'createdBy'>): Promise<ShiftPlan> {
const response = await fetch(API_BASE, {
method: 'POST',
headers: {
@@ -81,7 +65,7 @@ export const shiftTemplateService = {
return response.json();
},
async updateTemplate(id: string, template: Partial<TemplateShift>): Promise<TemplateShift> {
async updateTemplate(id: string, template: Partial<ShiftPlan>): Promise<ShiftPlan> {
const response = await fetch(`${API_BASE}/${id}`, {
method: 'PUT',
headers: {