mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-12-01 06:55:45 +01:00
set template shift struc
This commit is contained in:
@@ -50,7 +50,20 @@ export const shiftPlanService = {
|
||||
throw new Error('Fehler beim Laden der Schichtpläne');
|
||||
}
|
||||
|
||||
return 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> {
|
||||
@@ -69,7 +82,20 @@ export const shiftPlanService = {
|
||||
throw new Error('Schichtplan nicht gefunden');
|
||||
}
|
||||
|
||||
return response.json();
|
||||
const data = await response.json();
|
||||
|
||||
// Convert snake_case to camelCase
|
||||
return {
|
||||
id: data.id,
|
||||
name: data.name,
|
||||
startDate: data.start_date, // Convert here
|
||||
endDate: data.end_date, // Convert here
|
||||
templateId: data.template_id,
|
||||
status: data.status,
|
||||
createdBy: data.created_by,
|
||||
createdAt: data.created_at,
|
||||
shifts: data.shifts || []
|
||||
};
|
||||
},
|
||||
|
||||
async createShiftPlan(plan: CreateShiftPlanRequest): Promise<ShiftPlan> {
|
||||
@@ -130,5 +156,60 @@ export const shiftPlanService = {
|
||||
}
|
||||
throw new Error('Fehler beim Löschen des Schichtplans');
|
||||
}
|
||||
},
|
||||
|
||||
async updateShiftPlanShift(planId: string, shift: ShiftPlanShift): 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<ShiftPlanShift, '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');
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// frontend/src/services/shiftTemplateService.ts
|
||||
import { ShiftTemplate, TemplateShift } from '../types/shiftTemplate';
|
||||
import { TemplateShift } from '../types/shiftTemplate';
|
||||
import { authService } from './authService';
|
||||
|
||||
const API_BASE = 'http://localhost:3002/api/shift-templates';
|
||||
const API_BASE = 'http://localhost:3001/api/shift-templates';
|
||||
|
||||
export const shiftTemplateService = {
|
||||
async getTemplates(): Promise<ShiftTemplate[]> {
|
||||
async getTemplates(): Promise<TemplateShift[]> {
|
||||
const response = await fetch(API_BASE, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -23,14 +23,14 @@ export const shiftTemplateService = {
|
||||
|
||||
const templates = await response.json();
|
||||
// Sortiere die Vorlagen so, dass die Standard-Vorlage immer zuerst kommt
|
||||
return templates.sort((a: ShiftTemplate, b: ShiftTemplate) => {
|
||||
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();
|
||||
});
|
||||
},
|
||||
|
||||
async getTemplate(id: string): Promise<ShiftTemplate> {
|
||||
async getTemplate(id: string): Promise<TemplateShift> {
|
||||
const response = await fetch(`${API_BASE}/${id}`, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -49,7 +49,7 @@ export const shiftTemplateService = {
|
||||
return response.json();
|
||||
},
|
||||
|
||||
async createTemplate(template: Omit<ShiftTemplate, 'id' | 'createdAt' | 'createdBy'>): Promise<ShiftTemplate> {
|
||||
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) {
|
||||
@@ -81,7 +81,7 @@ export const shiftTemplateService = {
|
||||
return response.json();
|
||||
},
|
||||
|
||||
async updateTemplate(id: string, template: Partial<ShiftTemplate>): Promise<ShiftTemplate> {
|
||||
async updateTemplate(id: string, template: Partial<TemplateShift>): Promise<TemplateShift> {
|
||||
const response = await fetch(`${API_BASE}/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user