mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-12-01 15:05:45 +01:00
backend working
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
// routes/scheduling.ts
|
||||
import express from 'express';
|
||||
import { SchedulingService } from '../services/SchedulingService.js';
|
||||
|
||||
@@ -8,18 +7,56 @@ router.post('/generate-schedule', async (req, res) => {
|
||||
try {
|
||||
const { shiftPlan, employees, availabilities, constraints } = req.body;
|
||||
|
||||
console.log('Received scheduling request:', {
|
||||
shiftPlan: shiftPlan?.name,
|
||||
employeeCount: employees?.length,
|
||||
availabilityCount: availabilities?.length,
|
||||
constraintCount: constraints?.length
|
||||
});
|
||||
|
||||
// Validate required data
|
||||
if (!shiftPlan || !employees || !availabilities) {
|
||||
return res.status(400).json({
|
||||
error: 'Missing required data',
|
||||
details: {
|
||||
shiftPlan: !!shiftPlan,
|
||||
employees: !!employees,
|
||||
availabilities: !!availabilities
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const scheduler = new SchedulingService();
|
||||
const result = await scheduler.generateOptimalSchedule({
|
||||
shiftPlan,
|
||||
employees,
|
||||
availabilities,
|
||||
constraints
|
||||
constraints: constraints || []
|
||||
});
|
||||
|
||||
console.log('Scheduling completed:', {
|
||||
success: result.success,
|
||||
assignments: Object.keys(result.assignments).length,
|
||||
violations: result.violations.length
|
||||
});
|
||||
|
||||
res.json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Scheduling failed', details: error });
|
||||
console.error('Scheduling failed:', error);
|
||||
res.status(500).json({
|
||||
error: 'Scheduling failed',
|
||||
details: error instanceof Error ? error.message : 'Unknown error'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Health check for scheduling service
|
||||
router.get('/health', (req, res) => {
|
||||
res.json({
|
||||
status: 'ok',
|
||||
service: 'scheduling',
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user