From 75d4d86ef376452b061a757ef69503a7d50e5ec8 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Sat, 11 Oct 2025 19:57:04 +0200 Subject: [PATCH] backend without errors --- frontend/src/services/shiftPlanService.ts | 87 ++++++++++++++++++++++- 1 file changed, 84 insertions(+), 3 deletions(-) diff --git a/frontend/src/services/shiftPlanService.ts b/frontend/src/services/shiftPlanService.ts index e62e3be..59df458 100644 --- a/frontend/src/services/shiftPlanService.ts +++ b/frontend/src/services/shiftPlanService.ts @@ -21,7 +21,20 @@ export const shiftPlanService = { throw new Error('Fehler beim Laden der Schichtpläne'); } - return await response.json(); + 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 || [] + })); }, async getShiftPlan(id: string): Promise { @@ -40,7 +53,20 @@ export const shiftPlanService = { throw new Error('Schichtplan nicht gefunden'); } - return await response.json(); + 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 || [] + })); }, async createShiftPlan(plan: CreateShiftPlanRequest): Promise { @@ -101,5 +127,60 @@ export const shiftPlanService = { } throw new Error('Fehler beim Löschen des Schichtplans'); } + }, + + async updateShiftPlanShift(planId: string, shift: Shift): Promise { + 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): Promise { + 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 { + 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'); + } } -}; \ No newline at end of file +};