mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-11-30 22:45:46 +01:00
ein runtime error
This commit is contained in:
@@ -60,7 +60,7 @@ CREATE TABLE IF NOT EXISTS scheduled_shifts (
|
||||
required_employees INTEGER NOT NULL CHECK (required_employees >= 1 AND required_employees <= 10) DEFAULT 2,
|
||||
assigned_employees TEXT DEFAULT '[]', -- JSON array of employee IDs
|
||||
FOREIGN KEY (plan_id) REFERENCES shift_plans(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (time_slot_id) REFERENCES time_slots(id),
|
||||
FOREIGN KEY (time_slot_id) REFERENCES time_slots(id) ON DELETE CASCADE,
|
||||
UNIQUE(plan_id, date, time_slot_id)
|
||||
);
|
||||
|
||||
@@ -89,7 +89,7 @@ CREATE TABLE IF NOT EXISTS employee_availability (
|
||||
notes TEXT,
|
||||
FOREIGN KEY (employee_id) REFERENCES employees(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (plan_id) REFERENCES shift_plans(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (time_slot_id) REFERENCES time_slots(id),
|
||||
FOREIGN KEY (time_slot_id) REFERENCES time_slots(id) ON DELETE CASCADE,
|
||||
UNIQUE(employee_id, plan_id, day_of_week, time_slot_id)
|
||||
);
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ export function calculateTotalRequiredEmployees(plan: ShiftPlan): number {
|
||||
return plan.shifts.reduce((total, shift) => total + shift.requiredEmployees, 0);
|
||||
}
|
||||
|
||||
export function getScheduledShiftByDateAndTime(
|
||||
/*export function getScheduledShiftByDateAndTime(
|
||||
plan: ShiftPlan,
|
||||
date: string,
|
||||
timeSlotId: string
|
||||
@@ -86,7 +86,7 @@ export function getScheduledShiftByDateAndTime(
|
||||
return plan.scheduledShifts?.find(shift =>
|
||||
shift.date === date && shift.timeSlotId === timeSlotId
|
||||
);
|
||||
}
|
||||
}*/
|
||||
|
||||
export function canPublishPlan(plan: ShiftPlan): { canPublish: boolean; errors: string[] } {
|
||||
const errors: string[] = [];
|
||||
|
||||
30
backend/src/routes/scheduledShifts.ts
Normal file
30
backend/src/routes/scheduledShifts.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
// backend/src/routes/scheduledShifts.ts
|
||||
import express from 'express';
|
||||
import { authMiddleware, requireRole } from '../middleware/auth.js';
|
||||
import {
|
||||
regenerateScheduledShifts,
|
||||
generateScheduledShiftsForPlan,
|
||||
getScheduledShift,
|
||||
getScheduledShiftsFromPlan,
|
||||
updateScheduledShift
|
||||
} from '../controllers/shiftPlanController.js';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.use(authMiddleware);
|
||||
|
||||
|
||||
router.post('/:id/generate-shifts', requireRole(['admin', 'instandhalter']), generateScheduledShiftsForPlan);
|
||||
|
||||
router.post('/:id/regenerate-shifts', requireRole(['admin', 'instandhalter']), regenerateScheduledShifts);
|
||||
|
||||
// GET all scheduled shifts for a plan
|
||||
router.get('/plan/:planId', requireRole(['admin']), getScheduledShiftsFromPlan);
|
||||
|
||||
// GET specific scheduled shift
|
||||
router.get('/:id', requireRole(['admin']), getScheduledShift);
|
||||
|
||||
// UPDATE scheduled shift
|
||||
router.put('/:id', requireRole(['admin']), updateScheduledShift);
|
||||
|
||||
export default router;
|
||||
@@ -7,15 +7,8 @@ import {
|
||||
createShiftPlan,
|
||||
updateShiftPlan,
|
||||
deleteShiftPlan,
|
||||
//getTemplates,
|
||||
//createFromTemplate,
|
||||
createFromPreset,
|
||||
revertToDraft,
|
||||
regenerateScheduledShifts,
|
||||
generateScheduledShiftsForPlan,
|
||||
getScheduledShift,
|
||||
getScheduledShiftsFromPlan,
|
||||
updateScheduledShift
|
||||
} from '../controllers/shiftPlanController.js';
|
||||
|
||||
const router = express.Router();
|
||||
@@ -51,21 +44,4 @@ router.delete('/:id', requireRole(['admin', 'instandhalter']), deleteShiftPlan);
|
||||
// PUT revert published plan to draft
|
||||
router.put('/:id/revert-to-draft', requireRole(['admin', 'instandhalter']), revertToDraft);
|
||||
|
||||
|
||||
|
||||
// SCHEDULED SHIFTS
|
||||
|
||||
router.post('/:id/generate-shifts', requireRole(['admin', 'instandhalter']), generateScheduledShiftsForPlan);
|
||||
|
||||
router.post('/:id/regenerate-shifts', requireRole(['admin', 'instandhalter']), regenerateScheduledShifts);
|
||||
|
||||
// GET all scheduled shifts for a plan (for debugging)
|
||||
router.get('/plan/:planId', requireRole(['admin']), getScheduledShiftsFromPlan);
|
||||
|
||||
// GET specific scheduled shift
|
||||
router.get('/:id', requireRole(['admin']), getScheduledShift);
|
||||
|
||||
// UPDATE scheduled shift
|
||||
router.put('/:id', requireRole(['admin']), updateScheduledShift);
|
||||
|
||||
export default router;
|
||||
@@ -8,6 +8,7 @@ import authRoutes from './routes/auth.js';
|
||||
import employeeRoutes from './routes/employees.js';
|
||||
import shiftPlanRoutes from './routes/shiftPlans.js';
|
||||
import setupRoutes from './routes/setup.js';
|
||||
import scheduledShifts from './routes/scheduledShifts.js';
|
||||
|
||||
const app = express();
|
||||
const PORT = 3002;
|
||||
@@ -21,6 +22,7 @@ app.use('/api/setup', setupRoutes);
|
||||
app.use('/api/auth', authRoutes);
|
||||
app.use('/api/employees', employeeRoutes);
|
||||
app.use('/api/shift-plans', shiftPlanRoutes);
|
||||
app.use('/api/scheduled-shifts', scheduledShifts);
|
||||
|
||||
// Error handling middleware should come after routes
|
||||
app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
|
||||
Reference in New Issue
Block a user