mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-11-30 22:45:46 +01:00
backend without errors
This commit is contained in:
@@ -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<ShiftPlan> {
|
||||
@@ -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<ShiftPlan> {
|
||||
@@ -101,5 +127,60 @@ export const shiftPlanService = {
|
||||
}
|
||||
throw new Error('Fehler beim Löschen des Schichtplans');
|
||||
}
|
||||
},
|
||||
|
||||
async updateShiftPlanShift(planId: string, shift: Shift): 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<Shift, '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');
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user