mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-12-01 06:55:45 +01:00
Compare commits
20 Commits
v1.0.0
...
1231c8362f
| Author | SHA1 | Date | |
|---|---|---|---|
| 1231c8362f | |||
| 663eb61352 | |||
| 23f1dd7aa0 | |||
| 5319ed5d7a | |||
| 65ebf1748b | |||
| 4321763a2b | |||
| 24525043e9 | |||
| d870523685 | |||
| 50a1f1a9b9 | |||
| 1927937109 | |||
| b3b3250f23 | |||
| 5f8a6bef31 | |||
| a838ba44e8 | |||
| 1057fd9954 | |||
| bc73fcebd3 | |||
| 82533ae616 | |||
| 840b4384a5 | |||
| 5a8b7e89d7 | |||
| 289c80eea1 | |||
| 1884a16220 |
16
.env.template
Normal file
16
.env.template
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# === SCHICHTPLANER DOCKER COMPOSE ENVIRONMENT VARIABLES ===
|
||||||
|
# Diese Datei wird von docker-compose automatisch geladen
|
||||||
|
|
||||||
|
# Security
|
||||||
|
JWT_SECRET=${JWT_SECRET:-your-secret-key-please-change}
|
||||||
|
NODE_ENV=${NODE_ENV:-production}
|
||||||
|
|
||||||
|
# Database
|
||||||
|
DB_PATH=${DB_PATH:-/app/data/database.db}
|
||||||
|
|
||||||
|
# Server
|
||||||
|
PORT=${PORT:-3002}
|
||||||
|
|
||||||
|
# App Configuration
|
||||||
|
APP_TITLE="Shift Planning App"
|
||||||
|
ENABLE_PRO=${ENABLE_PRO:-false}
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -64,6 +64,7 @@ build/
|
|||||||
.env.development.local
|
.env.development.local
|
||||||
.env.test.local
|
.env.test.local
|
||||||
.env.production.local
|
.env.production.local
|
||||||
|
.env.production
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
database/*.db
|
database/*.db
|
||||||
|
|||||||
24
Dockerfile
24
Dockerfile
@@ -30,19 +30,24 @@ RUN npm install --workspace=frontend
|
|||||||
RUN npm run build --only=production --workspace=backend
|
RUN npm run build --only=production --workspace=backend
|
||||||
|
|
||||||
# Build frontend
|
# Build frontend
|
||||||
RUN npm run build --only=production --workspace=frontend
|
RUN npm run build --workspace=frontend
|
||||||
|
|
||||||
# Verify Python and OR-Tools installation
|
# Verify Python and OR-Tools installation
|
||||||
RUN python -c "from ortools.sat.python import cp_model; print('OR-Tools installed successfully')"
|
RUN python -c "from ortools.sat.python import cp_model; print('OR-Tools installed successfully')"
|
||||||
|
|
||||||
# Production stage (same as above)
|
# Production stage
|
||||||
FROM node:20-bookworm
|
FROM node:20-bookworm
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install system dependencies including gettext-base for envsubst
|
||||||
|
RUN apt-get update && apt-get install -y gettext-base && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
RUN npm install -g pm2
|
RUN npm install -g pm2
|
||||||
RUN mkdir -p /app/data
|
RUN mkdir -p /app/data
|
||||||
|
|
||||||
|
# Copy application files
|
||||||
COPY --from=builder /app/backend/dist/ ./dist/
|
COPY --from=builder /app/backend/dist/ ./dist/
|
||||||
COPY --from=builder /app/backend/package*.json ./
|
COPY --from=builder /app/backend/package*.json ./
|
||||||
|
|
||||||
@@ -54,6 +59,14 @@ COPY --from=builder /app/ecosystem.config.cjs ./
|
|||||||
COPY --from=builder /app/backend/src/database/ ./dist/database/
|
COPY --from=builder /app/backend/src/database/ ./dist/database/
|
||||||
COPY --from=builder /app/backend/src/database/ ./database/
|
COPY --from=builder /app/backend/src/database/ ./database/
|
||||||
|
|
||||||
|
# Copy init script and env template
|
||||||
|
COPY docker-init.sh /usr/local/bin/
|
||||||
|
COPY .env.template ./
|
||||||
|
|
||||||
|
# Set execute permissions for init script
|
||||||
|
RUN chmod +x /usr/local/bin/docker-init.sh
|
||||||
|
|
||||||
|
# Create user and set permissions
|
||||||
RUN groupadd -g 1001 nodejs && \
|
RUN groupadd -g 1001 nodejs && \
|
||||||
useradd -m -u 1001 -s /bin/bash -g nodejs schichtplan && \
|
useradd -m -u 1001 -s /bin/bash -g nodejs schichtplan && \
|
||||||
chown -R schichtplan:nodejs /app && \
|
chown -R schichtplan:nodejs /app && \
|
||||||
@@ -61,10 +74,13 @@ RUN groupadd -g 1001 nodejs && \
|
|||||||
chmod 775 /app/data
|
chmod 775 /app/data
|
||||||
|
|
||||||
ENV PM2_HOME=/app/.pm2
|
ENV PM2_HOME=/app/.pm2
|
||||||
|
|
||||||
|
# Set entrypoint to init script and keep existing cmd
|
||||||
|
ENTRYPOINT ["/usr/local/bin/docker-init.sh"]
|
||||||
|
CMD ["pm2-runtime", "ecosystem.config.cjs"]
|
||||||
|
|
||||||
USER schichtplan
|
USER schichtplan
|
||||||
EXPOSE 3002
|
EXPOSE 3002
|
||||||
|
|
||||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
||||||
CMD wget --no-verbose --tries=1 --spider http://localhost:3002/api/health || exit 1
|
CMD wget --no-verbose --tries=1 --spider http://localhost:3002/api/health || exit 1
|
||||||
|
|
||||||
CMD ["pm2-runtime", "ecosystem.config.cjs"]
|
|
||||||
@@ -16,15 +16,16 @@
|
|||||||
"@types/bcrypt": "^6.0.0",
|
"@types/bcrypt": "^6.0.0",
|
||||||
"bcrypt": "^6.0.0",
|
"bcrypt": "^6.0.0",
|
||||||
"bcryptjs": "^2.4.3",
|
"bcryptjs": "^2.4.3",
|
||||||
"cors": "^2.8.5",
|
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.2",
|
||||||
"sqlite3": "^5.1.6",
|
"sqlite3": "^5.1.6",
|
||||||
"uuid": "^9.0.0"
|
"uuid": "^9.0.0",
|
||||||
|
"express-rate-limit": "8.1.0",
|
||||||
|
"helmet": "8.1.0",
|
||||||
|
"express-validator": "7.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bcryptjs": "^2.4.2",
|
"@types/bcryptjs": "^2.4.2",
|
||||||
"@types/cors": "^2.8.13",
|
|
||||||
"@types/express": "^4.17.17",
|
"@types/express": "^4.17.17",
|
||||||
"@types/jsonwebtoken": "^9.0.2",
|
"@types/jsonwebtoken": "^9.0.2",
|
||||||
"@types/uuid": "^9.0.2",
|
"@types/uuid": "^9.0.2",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// backend/src/controllers/employeeController.ts
|
// backend/src/controllers/employeeController.ts
|
||||||
import { Request, Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import bcrypt from 'bcryptjs';
|
import bcrypt from 'bcryptjs';
|
||||||
import { db } from '../services/databaseService.js';
|
import { db } from '../services/databaseService.js';
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// backend/src/controllers/setupController.ts
|
// backend/src/controllers/setupController.ts
|
||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import bcrypt from 'bcrypt';
|
import bcrypt from 'bcrypt';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
|
||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
import { db } from '../services/databaseService.js';
|
import { db } from '../services/databaseService.js';
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,9 @@ import { db } from '../services/databaseService.js';
|
|||||||
import {
|
import {
|
||||||
CreateShiftPlanRequest,
|
CreateShiftPlanRequest,
|
||||||
UpdateShiftPlanRequest,
|
UpdateShiftPlanRequest,
|
||||||
ShiftPlan
|
|
||||||
} from '../models/ShiftPlan.js';
|
} from '../models/ShiftPlan.js';
|
||||||
import { AuthRequest } from '../middleware/auth.js';
|
import { AuthRequest } from '../middleware/auth.js';
|
||||||
import { createPlanFromPreset, TEMPLATE_PRESETS } from '../models/defaults/shiftPlanDefaults.js';
|
import { TEMPLATE_PRESETS } from '../models/defaults/shiftPlanDefaults.js';
|
||||||
|
|
||||||
async function getPlanWithDetails(planId: string) {
|
async function getPlanWithDetails(planId: string) {
|
||||||
const plan = await db.get<any>(`
|
const plan = await db.get<any>(`
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
PRAGMA journal_mode = WAL;
|
||||||
|
PRAGMA foreign_keys = ON;
|
||||||
|
PRAGMA secure_delete = ON;
|
||||||
|
PRAGMA auto_vacuum = INCREMENTAL;
|
||||||
|
|
||||||
-- Employee Types
|
-- Employee Types
|
||||||
CREATE TABLE IF NOT EXISTS employee_types (
|
CREATE TABLE IF NOT EXISTS employee_types (
|
||||||
type TEXT PRIMARY KEY,
|
type TEXT PRIMARY KEY,
|
||||||
|
|||||||
48
backend/src/middleware/rateLimit.ts
Normal file
48
backend/src/middleware/rateLimit.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import rateLimit from 'express-rate-limit';
|
||||||
|
import { Request } from 'express';
|
||||||
|
|
||||||
|
// Helper to check if request should be limited
|
||||||
|
const shouldSkipLimit = (req: Request): boolean => {
|
||||||
|
const skipPaths = [
|
||||||
|
'/api/health',
|
||||||
|
'/api/setup/status',
|
||||||
|
'/api/auth/validate'
|
||||||
|
];
|
||||||
|
|
||||||
|
// Skip for successful GET requests (data fetching)
|
||||||
|
if (req.method === 'GET' && req.path.startsWith('/api/')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return skipPaths.includes(req.path);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Main API limiter - nur für POST/PUT/DELETE
|
||||||
|
export const apiLimiter = rateLimit({
|
||||||
|
windowMs: 15 * 60 * 1000, // 15 minutes
|
||||||
|
max: 200, // 200 non-GET requests per 15 minutes
|
||||||
|
message: {
|
||||||
|
error: 'Zu viele Anfragen, bitte verlangsamen Sie Ihre Aktionen'
|
||||||
|
},
|
||||||
|
standardHeaders: true,
|
||||||
|
legacyHeaders: false,
|
||||||
|
skip: (req) => {
|
||||||
|
// ✅ Skip für GET requests (Data Fetching)
|
||||||
|
if (req.method === 'GET') return true;
|
||||||
|
|
||||||
|
// ✅ Skip für Health/Status Checks
|
||||||
|
return shouldSkipLimit(req);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Strict limiter for auth endpoints
|
||||||
|
export const authLimiter = rateLimit({
|
||||||
|
windowMs: 15 * 60 * 1000,
|
||||||
|
max: 5,
|
||||||
|
message: {
|
||||||
|
error: 'Zu viele Login-Versuche, bitte versuchen Sie es später erneut'
|
||||||
|
},
|
||||||
|
standardHeaders: true,
|
||||||
|
legacyHeaders: false,
|
||||||
|
skipSuccessfulRequests: true,
|
||||||
|
});
|
||||||
457
backend/src/middleware/validation.ts
Normal file
457
backend/src/middleware/validation.ts
Normal file
@@ -0,0 +1,457 @@
|
|||||||
|
import { body, validationResult, param, query } from 'express-validator';
|
||||||
|
import { Request, Response, NextFunction } from 'express';
|
||||||
|
|
||||||
|
// ===== AUTH VALIDATION =====
|
||||||
|
export const validateLogin = [
|
||||||
|
body('email')
|
||||||
|
.isEmail()
|
||||||
|
.withMessage('Must be a valid email')
|
||||||
|
.normalizeEmail(),
|
||||||
|
|
||||||
|
body('password')
|
||||||
|
.isLength({ min: 6 })
|
||||||
|
.withMessage('Password must be at least 6 characters')
|
||||||
|
.trim()
|
||||||
|
.escape()
|
||||||
|
];
|
||||||
|
|
||||||
|
export const validateRegister = [
|
||||||
|
body('firstname')
|
||||||
|
.isLength({ min: 1, max: 100 })
|
||||||
|
.withMessage('First name must be between 1-100 characters')
|
||||||
|
.trim()
|
||||||
|
.escape(),
|
||||||
|
|
||||||
|
body('lastname')
|
||||||
|
.isLength({ min: 1, max: 100 })
|
||||||
|
.withMessage('Last name must be between 1-100 characters')
|
||||||
|
.trim()
|
||||||
|
.escape(),
|
||||||
|
|
||||||
|
body('password')
|
||||||
|
.isLength({ min: 8 })
|
||||||
|
.withMessage('Password must be at least 8 characters')
|
||||||
|
.matches(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)/)
|
||||||
|
.withMessage('Password must contain uppercase, lowercase and number')
|
||||||
|
];
|
||||||
|
|
||||||
|
// ===== EMPLOYEE VALIDATION =====
|
||||||
|
export const validateEmployee = [
|
||||||
|
body('firstname')
|
||||||
|
.isLength({ min: 1, max: 100 })
|
||||||
|
.withMessage('First name must be between 1-100 characters')
|
||||||
|
.trim()
|
||||||
|
.escape(),
|
||||||
|
|
||||||
|
body('lastname')
|
||||||
|
.isLength({ min: 1, max: 100 })
|
||||||
|
.withMessage('Last name must be between 1-100 characters')
|
||||||
|
.trim()
|
||||||
|
.escape(),
|
||||||
|
|
||||||
|
body('password')
|
||||||
|
.optional()
|
||||||
|
.isLength({ min: 8 })
|
||||||
|
.withMessage('Password must be at least 8 characters')
|
||||||
|
.matches(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)/)
|
||||||
|
.withMessage('Password must contain uppercase, lowercase and number'),
|
||||||
|
|
||||||
|
body('employeeType')
|
||||||
|
.isIn(['manager', 'personell', 'apprentice', 'guest'])
|
||||||
|
.withMessage('Employee type must be manager, personell, apprentice or guest'),
|
||||||
|
|
||||||
|
body('contractType')
|
||||||
|
.optional()
|
||||||
|
.isIn(['small', 'large', 'flexible'])
|
||||||
|
.withMessage('Contract type must be small, large or flexible'),
|
||||||
|
|
||||||
|
body('roles')
|
||||||
|
.optional()
|
||||||
|
.isArray()
|
||||||
|
.withMessage('Roles must be an array'),
|
||||||
|
|
||||||
|
body('roles.*')
|
||||||
|
.optional()
|
||||||
|
.isIn(['admin', 'maintenance', 'user'])
|
||||||
|
.withMessage('Invalid role. Allowed: admin, maintenance, user'),
|
||||||
|
|
||||||
|
body('canWorkAlone')
|
||||||
|
.optional()
|
||||||
|
.isBoolean()
|
||||||
|
.withMessage('canWorkAlone must be a boolean'),
|
||||||
|
|
||||||
|
body('isTrainee')
|
||||||
|
.optional()
|
||||||
|
.isBoolean()
|
||||||
|
.withMessage('isTrainee must be a boolean'),
|
||||||
|
|
||||||
|
body('isActive')
|
||||||
|
.optional()
|
||||||
|
.isBoolean()
|
||||||
|
.withMessage('isActive must be a boolean')
|
||||||
|
];
|
||||||
|
|
||||||
|
export const validateEmployeeUpdate = [
|
||||||
|
body('firstname')
|
||||||
|
.optional()
|
||||||
|
.isLength({ min: 1, max: 100 })
|
||||||
|
.withMessage('First name must be between 1-100 characters')
|
||||||
|
.trim()
|
||||||
|
.escape(),
|
||||||
|
|
||||||
|
body('lastname')
|
||||||
|
.optional()
|
||||||
|
.isLength({ min: 1, max: 100 })
|
||||||
|
.withMessage('Last name must be between 1-100 characters')
|
||||||
|
.trim()
|
||||||
|
.escape(),
|
||||||
|
|
||||||
|
body('employeeType')
|
||||||
|
.optional()
|
||||||
|
.isIn(['manager', 'personell', 'apprentice', 'guest'])
|
||||||
|
.withMessage('Employee type must be manager, personell, apprentice or guest'),
|
||||||
|
|
||||||
|
body('contractType')
|
||||||
|
.optional()
|
||||||
|
.isIn(['small', 'large', 'flexible'])
|
||||||
|
.withMessage('Contract type must be small, large or flexible'),
|
||||||
|
|
||||||
|
body('roles')
|
||||||
|
.optional()
|
||||||
|
.isArray()
|
||||||
|
.withMessage('Roles must be an array'),
|
||||||
|
|
||||||
|
body('roles.*')
|
||||||
|
.optional()
|
||||||
|
.isIn(['admin', 'maintenance', 'user'])
|
||||||
|
.withMessage('Invalid role. Allowed: admin, maintenance, user'),
|
||||||
|
|
||||||
|
body('canWorkAlone')
|
||||||
|
.optional()
|
||||||
|
.isBoolean()
|
||||||
|
.withMessage('canWorkAlone must be a boolean'),
|
||||||
|
|
||||||
|
body('isTrainee')
|
||||||
|
.optional()
|
||||||
|
.isBoolean()
|
||||||
|
.withMessage('isTrainee must be a boolean'),
|
||||||
|
|
||||||
|
body('isActive')
|
||||||
|
.optional()
|
||||||
|
.isBoolean()
|
||||||
|
.withMessage('isActive must be a boolean')
|
||||||
|
];
|
||||||
|
|
||||||
|
export const validateChangePassword = [
|
||||||
|
body('currentPassword')
|
||||||
|
.optional()
|
||||||
|
.isLength({ min: 6 })
|
||||||
|
.withMessage('Current password must be at least 6 characters'),
|
||||||
|
|
||||||
|
body('newPassword')
|
||||||
|
.isLength({ min: 8 })
|
||||||
|
.withMessage('New password must be at least 8 characters')
|
||||||
|
.matches(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)/)
|
||||||
|
.withMessage('New password must contain uppercase, lowercase and number')
|
||||||
|
];
|
||||||
|
|
||||||
|
// ===== SHIFT PLAN VALIDATION =====
|
||||||
|
export const validateShiftPlan = [
|
||||||
|
body('name')
|
||||||
|
.isLength({ min: 1, max: 200 })
|
||||||
|
.withMessage('Name must be between 1-200 characters')
|
||||||
|
.trim()
|
||||||
|
.escape(),
|
||||||
|
|
||||||
|
body('description')
|
||||||
|
.optional()
|
||||||
|
.isLength({ max: 1000 })
|
||||||
|
.withMessage('Description cannot exceed 1000 characters')
|
||||||
|
.trim()
|
||||||
|
.escape(),
|
||||||
|
|
||||||
|
body('startDate')
|
||||||
|
.optional()
|
||||||
|
.isISO8601()
|
||||||
|
.withMessage('Must be a valid date (ISO format)'),
|
||||||
|
|
||||||
|
body('endDate')
|
||||||
|
.optional()
|
||||||
|
.isISO8601()
|
||||||
|
.withMessage('Must be a valid date (ISO format)'),
|
||||||
|
|
||||||
|
body('isTemplate')
|
||||||
|
.optional()
|
||||||
|
.isBoolean()
|
||||||
|
.withMessage('isTemplate must be a boolean'),
|
||||||
|
|
||||||
|
body('status')
|
||||||
|
.optional()
|
||||||
|
.isIn(['draft', 'published', 'archived', 'template'])
|
||||||
|
.withMessage('Status must be draft, published, archived or template'),
|
||||||
|
|
||||||
|
body('timeSlots')
|
||||||
|
.optional()
|
||||||
|
.isArray()
|
||||||
|
.withMessage('Time slots must be an array'),
|
||||||
|
|
||||||
|
body('timeSlots.*.name')
|
||||||
|
.isLength({ min: 1, max: 100 })
|
||||||
|
.withMessage('Time slot name must be between 1-100 characters')
|
||||||
|
.trim()
|
||||||
|
.escape(),
|
||||||
|
|
||||||
|
body('timeSlots.*.startTime')
|
||||||
|
.matches(/^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/)
|
||||||
|
.withMessage('Start time must be in HH:MM format'),
|
||||||
|
|
||||||
|
body('timeSlots.*.endTime')
|
||||||
|
.matches(/^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/)
|
||||||
|
.withMessage('End time must be in HH:MM format'),
|
||||||
|
|
||||||
|
body('timeSlots.*.description')
|
||||||
|
.optional()
|
||||||
|
.isLength({ max: 500 })
|
||||||
|
.withMessage('Time slot description cannot exceed 500 characters')
|
||||||
|
.trim()
|
||||||
|
.escape(),
|
||||||
|
|
||||||
|
body('shifts')
|
||||||
|
.optional()
|
||||||
|
.isArray()
|
||||||
|
.withMessage('Shifts must be an array'),
|
||||||
|
|
||||||
|
body('shifts.*.dayOfWeek')
|
||||||
|
.isInt({ min: 1, max: 7 })
|
||||||
|
.withMessage('Day of week must be between 1-7 (Monday-Sunday)'),
|
||||||
|
|
||||||
|
body('shifts.*.timeSlotId')
|
||||||
|
.isUUID()
|
||||||
|
.withMessage('Time slot ID must be a valid UUID'),
|
||||||
|
|
||||||
|
body('shifts.*.requiredEmployees')
|
||||||
|
.isInt({ min: 0 })
|
||||||
|
.withMessage('Required employees must be a positive integer'),
|
||||||
|
|
||||||
|
body('shifts.*.color')
|
||||||
|
.optional()
|
||||||
|
.isHexColor()
|
||||||
|
.withMessage('Color must be a valid hex color')
|
||||||
|
];
|
||||||
|
|
||||||
|
export const validateShiftPlanUpdate = [
|
||||||
|
body('name')
|
||||||
|
.optional()
|
||||||
|
.isLength({ min: 1, max: 200 })
|
||||||
|
.withMessage('Name must be between 1-200 characters')
|
||||||
|
.trim()
|
||||||
|
.escape(),
|
||||||
|
|
||||||
|
body('description')
|
||||||
|
.optional()
|
||||||
|
.isLength({ max: 1000 })
|
||||||
|
.withMessage('Description cannot exceed 1000 characters')
|
||||||
|
.trim()
|
||||||
|
.escape(),
|
||||||
|
|
||||||
|
body('startDate')
|
||||||
|
.optional()
|
||||||
|
.isISO8601()
|
||||||
|
.withMessage('Must be a valid date (ISO format)'),
|
||||||
|
|
||||||
|
body('endDate')
|
||||||
|
.optional()
|
||||||
|
.isISO8601()
|
||||||
|
.withMessage('Must be a valid date (ISO format)'),
|
||||||
|
|
||||||
|
body('status')
|
||||||
|
.optional()
|
||||||
|
.isIn(['draft', 'published', 'archived', 'template'])
|
||||||
|
.withMessage('Status must be draft, published, archived or template'),
|
||||||
|
|
||||||
|
body('timeSlots')
|
||||||
|
.optional()
|
||||||
|
.isArray()
|
||||||
|
.withMessage('Time slots must be an array'),
|
||||||
|
|
||||||
|
body('shifts')
|
||||||
|
.optional()
|
||||||
|
.isArray()
|
||||||
|
.withMessage('Shifts must be an array')
|
||||||
|
];
|
||||||
|
|
||||||
|
export const validateCreateFromPreset = [
|
||||||
|
body('presetName')
|
||||||
|
.isLength({ min: 1 })
|
||||||
|
.withMessage('Preset name is required')
|
||||||
|
.isIn(['standardWeek', 'extendedWeek', 'weekendFocused', 'morningOnly', 'eveningOnly', 'ZEBRA_STANDARD'])
|
||||||
|
.withMessage('Invalid preset name'),
|
||||||
|
|
||||||
|
body('name')
|
||||||
|
.isLength({ min: 1, max: 200 })
|
||||||
|
.withMessage('Name must be between 1-200 characters')
|
||||||
|
.trim()
|
||||||
|
.escape(),
|
||||||
|
|
||||||
|
body('startDate')
|
||||||
|
.optional()
|
||||||
|
.isISO8601()
|
||||||
|
.withMessage('Must be a valid date (ISO format)'),
|
||||||
|
|
||||||
|
body('endDate')
|
||||||
|
.optional()
|
||||||
|
.isISO8601()
|
||||||
|
.withMessage('Must be a valid date (ISO format)'),
|
||||||
|
|
||||||
|
body('isTemplate')
|
||||||
|
.optional()
|
||||||
|
.isBoolean()
|
||||||
|
.withMessage('isTemplate must be a boolean')
|
||||||
|
];
|
||||||
|
|
||||||
|
// ===== SCHEDULED SHIFTS VALIDATION =====
|
||||||
|
export const validateScheduledShiftUpdate = [
|
||||||
|
body('assignedEmployees')
|
||||||
|
.isArray()
|
||||||
|
.withMessage('assignedEmployees must be an array'),
|
||||||
|
|
||||||
|
body('assignedEmployees.*')
|
||||||
|
.isUUID()
|
||||||
|
.withMessage('Each assigned employee must be a valid UUID'),
|
||||||
|
|
||||||
|
body('requiredEmployees')
|
||||||
|
.optional()
|
||||||
|
.isInt({ min: 0 })
|
||||||
|
.withMessage('Required employees must be a positive integer')
|
||||||
|
];
|
||||||
|
|
||||||
|
// ===== SETUP VALIDATION =====
|
||||||
|
export const validateSetupAdmin = [
|
||||||
|
body('firstname')
|
||||||
|
.isLength({ min: 1, max: 100 })
|
||||||
|
.withMessage('First name must be between 1-100 characters')
|
||||||
|
.trim()
|
||||||
|
.escape(),
|
||||||
|
|
||||||
|
body('lastname')
|
||||||
|
.isLength({ min: 1, max: 100 })
|
||||||
|
.withMessage('Last name must be between 1-100 characters')
|
||||||
|
.trim()
|
||||||
|
.escape(),
|
||||||
|
|
||||||
|
body('password')
|
||||||
|
.isLength({ min: 8 })
|
||||||
|
.withMessage('Password must be at least 8 characters')
|
||||||
|
.matches(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)/)
|
||||||
|
.withMessage('Password must contain uppercase, lowercase and number')
|
||||||
|
];
|
||||||
|
|
||||||
|
// ===== SCHEDULING VALIDATION =====
|
||||||
|
export const validateSchedulingRequest = [
|
||||||
|
body('shiftPlan')
|
||||||
|
.isObject()
|
||||||
|
.withMessage('Shift plan is required'),
|
||||||
|
|
||||||
|
body('shiftPlan.id')
|
||||||
|
.isUUID()
|
||||||
|
.withMessage('Shift plan ID must be a valid UUID'),
|
||||||
|
|
||||||
|
body('employees')
|
||||||
|
.isArray({ min: 1 })
|
||||||
|
.withMessage('At least one employee is required'),
|
||||||
|
|
||||||
|
body('employees.*.id')
|
||||||
|
.isUUID()
|
||||||
|
.withMessage('Each employee must have a valid UUID'),
|
||||||
|
|
||||||
|
body('availabilities')
|
||||||
|
.isArray()
|
||||||
|
.withMessage('Availabilities must be an array'),
|
||||||
|
|
||||||
|
body('constraints')
|
||||||
|
.optional()
|
||||||
|
.isArray()
|
||||||
|
.withMessage('Constraints must be an array')
|
||||||
|
];
|
||||||
|
|
||||||
|
// ===== AVAILABILITY VALIDATION =====
|
||||||
|
export const validateAvailabilities = [
|
||||||
|
body('planId')
|
||||||
|
.isUUID()
|
||||||
|
.withMessage('Plan ID must be a valid UUID'),
|
||||||
|
|
||||||
|
body('availabilities')
|
||||||
|
.isArray()
|
||||||
|
.withMessage('Availabilities must be an array'),
|
||||||
|
|
||||||
|
body('availabilities.*.shiftId')
|
||||||
|
.isUUID()
|
||||||
|
.withMessage('Each shift ID must be a valid UUID'),
|
||||||
|
|
||||||
|
body('availabilities.*.preferenceLevel')
|
||||||
|
.isInt({ min: 0, max: 2 })
|
||||||
|
.withMessage('Preference level must be 0 (unavailable), 1 (available), or 2 (preferred)'),
|
||||||
|
|
||||||
|
body('availabilities.*.notes')
|
||||||
|
.optional()
|
||||||
|
.isLength({ max: 500 })
|
||||||
|
.withMessage('Notes cannot exceed 500 characters')
|
||||||
|
.trim()
|
||||||
|
.escape()
|
||||||
|
];
|
||||||
|
|
||||||
|
// ===== COMMON VALIDATORS =====
|
||||||
|
export const validateId = [
|
||||||
|
param('id')
|
||||||
|
.isUUID()
|
||||||
|
.withMessage('Must be a valid UUID')
|
||||||
|
];
|
||||||
|
|
||||||
|
export const validateEmployeeId = [
|
||||||
|
param('employeeId')
|
||||||
|
.isUUID()
|
||||||
|
.withMessage('Must be a valid UUID')
|
||||||
|
];
|
||||||
|
|
||||||
|
export const validatePlanId = [
|
||||||
|
param('planId')
|
||||||
|
.isUUID()
|
||||||
|
.withMessage('Must be a valid UUID')
|
||||||
|
];
|
||||||
|
|
||||||
|
export const validatePagination = [
|
||||||
|
query('page')
|
||||||
|
.optional()
|
||||||
|
.isInt({ min: 1 })
|
||||||
|
.withMessage('Page must be a positive integer'),
|
||||||
|
|
||||||
|
query('limit')
|
||||||
|
.optional()
|
||||||
|
.isInt({ min: 1, max: 100 })
|
||||||
|
.withMessage('Limit must be between 1-100'),
|
||||||
|
|
||||||
|
query('includeInactive')
|
||||||
|
.optional()
|
||||||
|
.isBoolean()
|
||||||
|
.withMessage('includeInactive must be a boolean')
|
||||||
|
];
|
||||||
|
|
||||||
|
// ===== MIDDLEWARE TO CHECK VALIDATION RESULTS =====
|
||||||
|
export const handleValidationErrors = (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
const errors = validationResult(req);
|
||||||
|
|
||||||
|
if (!errors.isEmpty()) {
|
||||||
|
const errorMessages = errors.array().map(error => ({
|
||||||
|
field: error.type === 'field' ? error.path : error.type,
|
||||||
|
message: error.msg,
|
||||||
|
value: error.msg
|
||||||
|
}));
|
||||||
|
|
||||||
|
return res.status(400).json({
|
||||||
|
error: 'Validation failed',
|
||||||
|
details: errorMessages
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
next();
|
||||||
|
};
|
||||||
@@ -8,12 +8,13 @@ import {
|
|||||||
validateToken
|
validateToken
|
||||||
} from '../controllers/authController.js';
|
} from '../controllers/authController.js';
|
||||||
import { authMiddleware } from '../middleware/auth.js';
|
import { authMiddleware } from '../middleware/auth.js';
|
||||||
|
import { validateLogin, validateRegister, handleValidationErrors } from '../middleware/validation.js';
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
// Public routes
|
// Public routes
|
||||||
router.post('/login', login);
|
router.post('/login', validateLogin, handleValidationErrors, login);
|
||||||
router.post('/register', register);
|
router.post('/register', validateRegister, handleValidationErrors, register);
|
||||||
router.get('/validate', validateToken);
|
router.get('/validate', validateToken);
|
||||||
|
|
||||||
// Protected routes (require authentication)
|
// Protected routes (require authentication)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// backend/src/routes/employees.ts
|
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import { authMiddleware, requireRole } from '../middleware/auth.js';
|
import { authMiddleware, requireRole } from '../middleware/auth.js';
|
||||||
import {
|
import {
|
||||||
@@ -12,6 +11,16 @@ import {
|
|||||||
changePassword,
|
changePassword,
|
||||||
updateLastLogin
|
updateLastLogin
|
||||||
} from '../controllers/employeeController.js';
|
} from '../controllers/employeeController.js';
|
||||||
|
import {
|
||||||
|
handleValidationErrors,
|
||||||
|
validateEmployee,
|
||||||
|
validateEmployeeUpdate,
|
||||||
|
validateChangePassword,
|
||||||
|
validateId,
|
||||||
|
validateEmployeeId,
|
||||||
|
validateAvailabilities,
|
||||||
|
validatePagination
|
||||||
|
} from '../middleware/validation.js';
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
@@ -19,16 +28,18 @@ const router = express.Router();
|
|||||||
router.use(authMiddleware);
|
router.use(authMiddleware);
|
||||||
|
|
||||||
// Employee CRUD Routes
|
// Employee CRUD Routes
|
||||||
router.get('/', authMiddleware, getEmployees);
|
router.get('/', validatePagination, handleValidationErrors, getEmployees);
|
||||||
router.get('/:id', requireRole(['admin', 'maintenance']), getEmployee);
|
router.get('/:id', validateId, handleValidationErrors, requireRole(['admin', 'maintenance']), getEmployee);
|
||||||
router.post('/', requireRole(['admin']), createEmployee);
|
router.post('/', validateEmployee, handleValidationErrors, requireRole(['admin']), createEmployee);
|
||||||
router.put('/:id', requireRole(['admin', 'maintenance']), updateEmployee);
|
router.put('/:id', validateId, validateEmployeeUpdate, handleValidationErrors, requireRole(['admin', 'maintenance']), updateEmployee);
|
||||||
router.delete('/:id', requireRole(['admin']), deleteEmployee);
|
router.delete('/:id', validateId, handleValidationErrors, requireRole(['admin']), deleteEmployee);
|
||||||
router.put('/:id/password', authMiddleware, changePassword);
|
|
||||||
router.put('/:id/last-login', authMiddleware, updateLastLogin);
|
// Password & Login Routes
|
||||||
|
router.put('/:id/password', validateId, validateChangePassword, handleValidationErrors, changePassword);
|
||||||
|
router.put('/:id/last-login', validateId, handleValidationErrors, updateLastLogin);
|
||||||
|
|
||||||
// Availability Routes
|
// Availability Routes
|
||||||
router.get('/:employeeId/availabilities', authMiddleware, getAvailabilities);
|
router.get('/:employeeId/availabilities', validateEmployeeId, handleValidationErrors, getAvailabilities);
|
||||||
router.put('/:employeeId/availabilities', authMiddleware, updateAvailabilities);
|
router.put('/:employeeId/availabilities', validateEmployeeId, validateAvailabilities, handleValidationErrors, updateAvailabilities);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
// backend/src/routes/scheduledShifts.ts
|
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import { authMiddleware, requireRole } from '../middleware/auth.js';
|
import { authMiddleware, requireRole } from '../middleware/auth.js';
|
||||||
import {
|
import {
|
||||||
@@ -8,23 +7,21 @@ import {
|
|||||||
getScheduledShiftsFromPlan,
|
getScheduledShiftsFromPlan,
|
||||||
updateScheduledShift
|
updateScheduledShift
|
||||||
} from '../controllers/shiftPlanController.js';
|
} from '../controllers/shiftPlanController.js';
|
||||||
|
import {
|
||||||
|
validateId,
|
||||||
|
validatePlanId,
|
||||||
|
validateScheduledShiftUpdate,
|
||||||
|
handleValidationErrors
|
||||||
|
} from '../middleware/validation.js';
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
router.use(authMiddleware);
|
router.use(authMiddleware);
|
||||||
|
|
||||||
|
router.post('/:id/generate-shifts', validateId, handleValidationErrors, requireRole(['admin', 'maintenance']), generateScheduledShiftsForPlan);
|
||||||
router.post('/:id/generate-shifts', requireRole(['admin', 'maintenance']), generateScheduledShiftsForPlan);
|
router.post('/:id/regenerate-shifts', validateId, handleValidationErrors, requireRole(['admin', 'maintenance']), regenerateScheduledShifts);
|
||||||
|
router.get('/plan/:planId', validatePlanId, handleValidationErrors, getScheduledShiftsFromPlan);
|
||||||
router.post('/:id/regenerate-shifts', requireRole(['admin', 'maintenance']), regenerateScheduledShifts);
|
router.get('/:id', validateId, handleValidationErrors, getScheduledShift);
|
||||||
|
router.put('/:id', validateId, validateScheduledShiftUpdate, handleValidationErrors, updateScheduledShift);
|
||||||
// GET all scheduled shifts for a plan
|
|
||||||
router.get('/plan/:planId', authMiddleware, getScheduledShiftsFromPlan);
|
|
||||||
|
|
||||||
// GET specific scheduled shift
|
|
||||||
router.get('/:id', authMiddleware, getScheduledShift);
|
|
||||||
|
|
||||||
// UPDATE scheduled shift
|
|
||||||
router.put('/:id', authMiddleware, updateScheduledShift);
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
import express from 'express';
|
import express from 'express';
|
||||||
import { SchedulingService } from '../services/SchedulingService.js';
|
import { SchedulingService } from '../services/SchedulingService.js';
|
||||||
|
import { validateSchedulingRequest, handleValidationErrors } from '../middleware/validation.js';
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
router.post('/generate-schedule', async (req, res) => {
|
router.post('/generate-schedule', validateSchedulingRequest, handleValidationErrors, async (req: express.Request, res: express.Response) => {
|
||||||
try {
|
try {
|
||||||
const { shiftPlan, employees, availabilities, constraints } = req.body;
|
const { shiftPlan, employees, availabilities, constraints } = req.body;
|
||||||
|
|
||||||
@@ -14,18 +15,6 @@ router.post('/generate-schedule', async (req, res) => {
|
|||||||
constraintCount: constraints?.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 scheduler = new SchedulingService();
|
||||||
const result = await scheduler.generateOptimalSchedule({
|
const result = await scheduler.generateOptimalSchedule({
|
||||||
shiftPlan,
|
shiftPlan,
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
// backend/src/routes/setup.ts
|
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import bcrypt from 'bcryptjs';
|
|
||||||
import { checkSetupStatus, setupAdmin } from '../controllers/setupController.js';
|
import { checkSetupStatus, setupAdmin } from '../controllers/setupController.js';
|
||||||
|
import { validateSetupAdmin, handleValidationErrors } from '../middleware/validation.js';
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
router.get('/status', checkSetupStatus);
|
router.get('/status', checkSetupStatus);
|
||||||
router.post('/admin', setupAdmin);
|
router.post('/admin', validateSetupAdmin, handleValidationErrors, setupAdmin);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
// backend/src/routes/shiftPlans.ts
|
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import { authMiddleware, requireRole } from '../middleware/auth.js';
|
import { authMiddleware, requireRole } from '../middleware/auth.js';
|
||||||
import {
|
import {
|
||||||
@@ -10,32 +9,25 @@ import {
|
|||||||
createFromPreset,
|
createFromPreset,
|
||||||
clearAssignments
|
clearAssignments
|
||||||
} from '../controllers/shiftPlanController.js';
|
} from '../controllers/shiftPlanController.js';
|
||||||
|
import {
|
||||||
|
validateShiftPlan,
|
||||||
|
validateShiftPlanUpdate,
|
||||||
|
validateCreateFromPreset,
|
||||||
|
handleValidationErrors,
|
||||||
|
validateId
|
||||||
|
} from '../middleware/validation.js';
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
router.use(authMiddleware);
|
router.use(authMiddleware);
|
||||||
|
|
||||||
// Combined routes for both shift plans and templates
|
// Combined routes for both shift plans and templates
|
||||||
|
router.get('/', getShiftPlans);
|
||||||
// GET all shift plans (including templates)
|
router.get('/:id', validateId, handleValidationErrors, getShiftPlan);
|
||||||
router.get('/' , authMiddleware, getShiftPlans);
|
router.post('/', validateShiftPlan, handleValidationErrors, requireRole(['admin', 'maintenance']), createShiftPlan);
|
||||||
|
router.post('/from-preset', validateCreateFromPreset, handleValidationErrors, requireRole(['admin', 'maintenance']), createFromPreset);
|
||||||
// GET specific shift plan or template
|
router.put('/:id', validateId, validateShiftPlanUpdate, handleValidationErrors, requireRole(['admin', 'maintenance']), updateShiftPlan);
|
||||||
router.get('/:id', authMiddleware, getShiftPlan);
|
router.delete('/:id', validateId, handleValidationErrors, requireRole(['admin', 'maintenance']), deleteShiftPlan);
|
||||||
|
router.post('/:id/clear-assignments', validateId, handleValidationErrors, requireRole(['admin', 'maintenance']), clearAssignments);
|
||||||
// POST create new shift plan
|
|
||||||
router.post('/', requireRole(['admin', 'maintenance']), createShiftPlan);
|
|
||||||
|
|
||||||
// POST create new plan from preset
|
|
||||||
router.post('/from-preset', requireRole(['admin', 'maintenance']), createFromPreset);
|
|
||||||
|
|
||||||
// PUT update shift plan or template
|
|
||||||
router.put('/:id', requireRole(['admin', 'maintenance']), updateShiftPlan);
|
|
||||||
|
|
||||||
// DELETE shift plan or template
|
|
||||||
router.delete('/:id', requireRole(['admin', 'maintenance']), deleteShiftPlan);
|
|
||||||
|
|
||||||
// POST clear assignments and reset to draft
|
|
||||||
router.post('/:id/clear-assignments', requireRole(['admin', 'maintenance']), clearAssignments);
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import { spawn } from 'child_process';
|
import { spawn } from 'child_process';
|
||||||
import path from 'path';
|
|
||||||
|
|
||||||
export function runPythonScript(scriptPath, args = []) {
|
export function runPythonScript(scriptPath, args = []) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import path from 'path';
|
|||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import { initializeDatabase } from './scripts/initializeDatabase.js';
|
import { initializeDatabase } from './scripts/initializeDatabase.js';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import helmet from 'helmet';
|
||||||
|
|
||||||
// Route imports
|
// Route imports
|
||||||
import authRoutes from './routes/auth.js';
|
import authRoutes from './routes/auth.js';
|
||||||
@@ -12,145 +13,192 @@ import shiftPlanRoutes from './routes/shiftPlans.js';
|
|||||||
import setupRoutes from './routes/setup.js';
|
import setupRoutes from './routes/setup.js';
|
||||||
import scheduledShifts from './routes/scheduledShifts.js';
|
import scheduledShifts from './routes/scheduledShifts.js';
|
||||||
import schedulingRoutes from './routes/scheduling.js';
|
import schedulingRoutes from './routes/scheduling.js';
|
||||||
|
import { authLimiter, apiLimiter } from './middleware/rateLimit.js';
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = 3002;
|
const PORT = 3002;
|
||||||
|
const isDevelopment = process.env.NODE_ENV === 'development';
|
||||||
|
|
||||||
|
app.set('trust proxy', true);
|
||||||
|
|
||||||
|
// Security configuration
|
||||||
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
console.info('Checking for JWT_SECRET');
|
||||||
|
const JWT_SECRET = process.env.JWT_SECRET;
|
||||||
|
if (!JWT_SECRET || JWT_SECRET === 'your-secret-key-please-change') {
|
||||||
|
console.error('❌ Fatal: JWT_SECRET not set or using default value');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Security headers
|
||||||
|
app.use(helmet({
|
||||||
|
contentSecurityPolicy: {
|
||||||
|
directives: {
|
||||||
|
defaultSrc: ["'self'"],
|
||||||
|
scriptSrc: ["'self'", "'unsafe-inline'"],
|
||||||
|
styleSrc: ["'self'", "'unsafe-inline'"],
|
||||||
|
imgSrc: ["'self'", "data:", "https:"],
|
||||||
|
connectSrc: ["'self'"],
|
||||||
|
fontSrc: ["'self'"],
|
||||||
|
objectSrc: ["'none'"],
|
||||||
|
mediaSrc: ["'self'"],
|
||||||
|
frameSrc: ["'none'"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
hsts: false,
|
||||||
|
crossOriginEmbedderPolicy: false
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Additional security headers
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
res.setHeader('X-Content-Type-Options', 'nosniff');
|
||||||
|
res.setHeader('X-Frame-Options', 'DENY');
|
||||||
|
res.setHeader('X-XSS-Protection', '1; mode=block');
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
// Middleware
|
// Middleware
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
|
// Rate limiting - weniger restriktiv in Development
|
||||||
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
app.use('/api/', apiLimiter);
|
||||||
|
} else {
|
||||||
|
console.log('🔧 Development: Rate limiting relaxed');
|
||||||
|
}
|
||||||
|
|
||||||
// API Routes
|
// API Routes
|
||||||
app.use('/api/setup', setupRoutes);
|
app.use('/api/setup', setupRoutes);
|
||||||
app.use('/api/auth', authRoutes);
|
app.use('/api/auth', authLimiter, authRoutes);
|
||||||
app.use('/api/employees', employeeRoutes);
|
app.use('/api/employees', employeeRoutes);
|
||||||
app.use('/api/shift-plans', shiftPlanRoutes);
|
app.use('/api/shift-plans', shiftPlanRoutes);
|
||||||
app.use('/api/scheduled-shifts', scheduledShifts);
|
app.use('/api/scheduled-shifts', scheduledShifts);
|
||||||
app.use('/api/scheduling', schedulingRoutes);
|
app.use('/api/scheduling', schedulingRoutes);
|
||||||
|
|
||||||
// Health route
|
// Health route
|
||||||
app.get('/api/health', (req: any, res: any) => {
|
app.get('/api/health', (req: express.Request, res: express.Response) => {
|
||||||
res.json({
|
res.json({
|
||||||
status: 'OK',
|
status: 'OK',
|
||||||
message: 'Backend läuft!',
|
message: 'Backend läuft!',
|
||||||
timestamp: new Date().toISOString()
|
timestamp: new Date().toISOString(),
|
||||||
|
mode: process.env.NODE_ENV || 'development'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// 🆕 FIXED STATIC FILE SERVING
|
// 🆕 IMPROVED STATIC FILE SERVING
|
||||||
// Use absolute path that matches Docker container structure
|
const findFrontendBuildPath = (): string | null => {
|
||||||
const frontendBuildPathEnv = process.env.FRONTEND_BUILD_PATH;
|
|
||||||
console.log('📁 Frontend build path from the env', frontendBuildPathEnv);
|
|
||||||
const frontendBuildPath = path.resolve('/app/frontend-build');
|
|
||||||
console.log('📁 Frontend build path:', frontendBuildPath);
|
|
||||||
console.log('📁 Current __dirname:', __dirname);
|
|
||||||
|
|
||||||
// Check multiple possible locations for frontend build
|
|
||||||
const possiblePaths = [
|
const possiblePaths = [
|
||||||
'/app/frontend-build', // Docker production path
|
// Production path (Docker)
|
||||||
path.join(__dirname, '../../frontend-build'), // Relative from dist
|
'/app/frontend-build',
|
||||||
path.join(process.cwd(), 'frontend-build'), // From current working directory
|
// Development paths
|
||||||
|
path.resolve(__dirname, '../../frontend/dist'),
|
||||||
|
path.resolve(__dirname, '../../frontend-build'),
|
||||||
|
path.resolve(process.cwd(), '../frontend/dist'),
|
||||||
|
path.resolve(process.cwd(), 'frontend-build'),
|
||||||
];
|
];
|
||||||
|
|
||||||
let actualFrontendPath = null;
|
|
||||||
for (const testPath of possiblePaths) {
|
for (const testPath of possiblePaths) {
|
||||||
if (fs.existsSync(testPath)) {
|
|
||||||
actualFrontendPath = testPath;
|
|
||||||
console.log('✅ Found frontend build at:', testPath);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (actualFrontendPath) {
|
|
||||||
// Serviere statische Dateien
|
|
||||||
app.use(express.static(actualFrontendPath));
|
|
||||||
|
|
||||||
// List files for debugging
|
|
||||||
try {
|
try {
|
||||||
const files = fs.readdirSync(actualFrontendPath);
|
if (fs.existsSync(testPath)) {
|
||||||
console.log('📄 Files in frontend-build:', files);
|
const indexPath = path.join(testPath, 'index.html');
|
||||||
} catch (err) {
|
if (fs.existsSync(indexPath)) {
|
||||||
console.log('❌ Could not read frontend-build directory:', err);
|
console.log('✅ Found frontend build at:', testPath);
|
||||||
|
return testPath;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// Silent catch - just try next path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const frontendBuildPath = findFrontendBuildPath();
|
||||||
|
|
||||||
|
if (frontendBuildPath) {
|
||||||
|
app.use(express.static(frontendBuildPath));
|
||||||
console.log('✅ Static file serving configured');
|
console.log('✅ Static file serving configured');
|
||||||
} else {
|
} else {
|
||||||
console.log('❌ Frontend build directory NOT FOUND in any location');
|
console.log(isDevelopment ?
|
||||||
console.log('❌ Checked paths:', possiblePaths);
|
'🔧 Development: Frontend served by Vite dev server (localhost:3003)' :
|
||||||
|
'❌ Production: No frontend build found'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Root route
|
// Root route
|
||||||
app.get('/', (req, res) => {
|
app.get('/', (req, res) => {
|
||||||
if (!actualFrontendPath) {
|
if (!frontendBuildPath) {
|
||||||
|
if (isDevelopment) {
|
||||||
|
return res.redirect('http://localhost:3003');
|
||||||
|
}
|
||||||
return res.status(500).send('Frontend build not found');
|
return res.status(500).send('Frontend build not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
const indexPath = path.join(actualFrontendPath, 'index.html');
|
const indexPath = path.join(frontendBuildPath, 'index.html');
|
||||||
console.log('📄 Serving index.html from:', indexPath);
|
|
||||||
|
|
||||||
if (fs.existsSync(indexPath)) {
|
|
||||||
res.sendFile(indexPath);
|
res.sendFile(indexPath);
|
||||||
} else {
|
|
||||||
console.error('❌ index.html not found at:', indexPath);
|
|
||||||
res.status(404).send('Frontend not found - index.html missing');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Client-side routing fallback
|
// Client-side routing fallback
|
||||||
app.get('*', (req, res) => {
|
app.get('*', (req, res) => {
|
||||||
// Ignoriere API Routes
|
|
||||||
if (req.path.startsWith('/api/')) {
|
if (req.path.startsWith('/api/')) {
|
||||||
return res.status(404).json({ error: 'API endpoint not found' });
|
return res.status(404).json({ error: 'API endpoint not found' });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!actualFrontendPath) {
|
if (!frontendBuildPath) {
|
||||||
|
if (isDevelopment) {
|
||||||
|
return res.redirect(`http://localhost:3003${req.path}`);
|
||||||
|
}
|
||||||
return res.status(500).json({ error: 'Frontend application not available' });
|
return res.status(500).json({ error: 'Frontend application not available' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const indexPath = path.join(actualFrontendPath, 'index.html');
|
const indexPath = path.join(frontendBuildPath, 'index.html');
|
||||||
console.log('🔄 Client-side routing for:', req.path, '->', indexPath);
|
res.sendFile(indexPath);
|
||||||
|
});
|
||||||
|
|
||||||
if (fs.existsSync(indexPath)) {
|
// Error handling
|
||||||
// Use absolute path with res.sendFile
|
app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
res.sendFile(indexPath, (err) => {
|
console.error('Error:', err);
|
||||||
if (err) {
|
|
||||||
console.error('Error sending index.html:', err);
|
if (process.env.NODE_ENV === 'production') {
|
||||||
res.status(500).send('Error loading application');
|
res.status(500).json({
|
||||||
}
|
error: 'Internal server error',
|
||||||
|
message: 'Something went wrong'
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.error('❌ index.html not found for client-side routing at:', indexPath);
|
res.status(500).json({
|
||||||
res.status(404).json({ error: 'Frontend application not found' });
|
error: 'Internal server error',
|
||||||
|
message: err.message,
|
||||||
|
stack: err.stack
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Error handling middleware
|
// 404 handling
|
||||||
app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {
|
app.use('*', (req, res) => {
|
||||||
console.error('Unhandled error:', err);
|
res.status(404).json({ error: 'Endpoint not found' });
|
||||||
res.status(500).json({ error: 'Internal server error' });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Initialize the application
|
// Initialize the application
|
||||||
const initializeApp = async () => {
|
const initializeApp = async () => {
|
||||||
try {
|
try {
|
||||||
// Initialize database with base schema
|
|
||||||
await initializeDatabase();
|
await initializeDatabase();
|
||||||
|
|
||||||
// Apply any pending migrations
|
|
||||||
const { applyMigration } = await import('./scripts/applyMigration.js');
|
const { applyMigration } = await import('./scripts/applyMigration.js');
|
||||||
await applyMigration();
|
await applyMigration();
|
||||||
|
|
||||||
// Start server only after successful initialization
|
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
console.log('🎉 APPLICATION STARTED SUCCESSFULLY!');
|
console.log('🎉 APPLICATION STARTED SUCCESSFULLY!');
|
||||||
console.log(`📍 Port: ${PORT}`);
|
console.log(`📍 Port: ${PORT}`);
|
||||||
|
console.log(`📍 Mode: ${process.env.NODE_ENV || 'development'}`);
|
||||||
|
if (frontendBuildPath) {
|
||||||
console.log(`📍 Frontend: http://localhost:${PORT}`);
|
console.log(`📍 Frontend: http://localhost:${PORT}`);
|
||||||
|
} else if (isDevelopment) {
|
||||||
|
console.log(`📍 Frontend (Vite): http://localhost:3003`);
|
||||||
|
}
|
||||||
console.log(`📍 API: http://localhost:${PORT}/api`);
|
console.log(`📍 API: http://localhost:${PORT}/api`);
|
||||||
console.log('');
|
|
||||||
console.log(`🔧 Setup: http://localhost:${PORT}/api/setup/status`);
|
|
||||||
console.log('📝 Create your admin account on first launch');
|
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('❌ Error during initialization:', error);
|
console.error('❌ Error during initialization:', error);
|
||||||
@@ -158,5 +206,4 @@ const initializeApp = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Start the application
|
|
||||||
initializeApp();
|
initializeApp();
|
||||||
@@ -2,8 +2,7 @@
|
|||||||
import { Worker } from 'worker_threads';
|
import { Worker } from 'worker_threads';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import { Employee, EmployeeAvailability } from '../models/Employee.js';
|
import { ShiftPlan } from '../models/ShiftPlan.js';
|
||||||
import { ShiftPlan, ScheduledShift } from '../models/ShiftPlan.js';
|
|
||||||
import { ScheduleRequest, ScheduleResult, Availability, Constraint } from '../models/scheduling.js';
|
import { ScheduleRequest, ScheduleResult, Availability, Constraint } from '../models/scheduling.js';
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
import { parentPort, workerData } from 'worker_threads';
|
import { parentPort, workerData } from 'worker_threads';
|
||||||
import { CPModel, CPSolver } from './cp-sat-wrapper.js';
|
import { CPModel, CPSolver } from './cp-sat-wrapper.js';
|
||||||
import { ShiftPlan, Shift } from '../models/ShiftPlan.js';
|
import { ShiftPlan, Shift } from '../models/ShiftPlan.js';
|
||||||
import { Employee, EmployeeAvailability } from '../models/Employee.js';
|
import { Employee } from '../models/Employee.js';
|
||||||
import { Availability, Constraint, Violation, SolverOptions, Solution, Assignment } from '../models/scheduling.js';
|
import { Availability, Constraint } from '../models/scheduling.js';
|
||||||
|
|
||||||
interface WorkerData {
|
interface WorkerData {
|
||||||
shiftPlan: ShiftPlan;
|
shiftPlan: ShiftPlan;
|
||||||
|
|||||||
@@ -4,11 +4,19 @@ services:
|
|||||||
schichtplaner:
|
schichtplaner:
|
||||||
container_name: schichtplaner
|
container_name: schichtplaner
|
||||||
image: ghcr.io/donpat1to/schichtenplaner:v1.0.0
|
image: ghcr.io/donpat1to/schichtenplaner:v1.0.0
|
||||||
|
environment:
|
||||||
|
- NODE_ENV=production
|
||||||
|
- JWT_SECRET=${JWT_SECRET:-your-secret-key-please-change}
|
||||||
ports:
|
ports:
|
||||||
- "3002:3002"
|
- "3002:3002"
|
||||||
volumes:
|
volumes:
|
||||||
- app_data:/app/data
|
- app_data:/app/data
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "curl", "-f", "http://localhost:3002/api/health"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
app_data:
|
app_data:
|
||||||
50
docker-init.sh
Normal file
50
docker-init.sh
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "🚀 Container Initialisierung gestartet..."
|
||||||
|
|
||||||
|
# Funktion zum Generieren eines sicheren Secrets
|
||||||
|
generate_secret() {
|
||||||
|
length=$1
|
||||||
|
tr -dc 'A-Za-z0-9!@#$%^&*()_+-=' < /dev/urandom | head -c $length
|
||||||
|
}
|
||||||
|
|
||||||
|
# Prüfe ob .env existiert
|
||||||
|
if [ ! -f /app/.env ]; then
|
||||||
|
echo "📝 Erstelle .env Datei..."
|
||||||
|
|
||||||
|
# Verwende vorhandenes JWT_SECRET oder generiere ein neues
|
||||||
|
if [ -z "$JWT_SECRET" ] || [ "$JWT_SECRET" = "your-secret-key-please-change" ]; then
|
||||||
|
export JWT_SECRET=$(generate_secret 64)
|
||||||
|
echo "🔑 Automatisch sicheres JWT Secret generiert"
|
||||||
|
else
|
||||||
|
echo "🔑 Verwende vorhandenes JWT Secret aus Umgebungsvariable"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Erstelle .env aus Template mit envsubst
|
||||||
|
envsubst < /app/.env.template > /app/.env
|
||||||
|
echo "✅ .env Datei erstellt"
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "ℹ️ .env Datei existiert bereits"
|
||||||
|
|
||||||
|
# Wenn .env existiert, aber JWT_SECRET Umgebungsvariable gesetzt ist, aktualisiere sie
|
||||||
|
if [ -n "$JWT_SECRET" ] && [ "$JWT_SECRET" != "your-secret-key-please-change" ]; then
|
||||||
|
echo "🔑 Aktualisiere JWT Secret in .env Datei"
|
||||||
|
# Aktualisiere nur das JWT_SECRET in der .env Datei
|
||||||
|
sed -i "s/^JWT_SECRET=.*/JWT_SECRET=$JWT_SECRET/" /app/.env
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Validiere dass JWT_SECERT nicht der Standardwert ist
|
||||||
|
if grep -q "JWT_SECRET=your-secret-key-please-change" /app/.env; then
|
||||||
|
echo "❌ FEHLER: Standard JWT Secret in .env gefunden!"
|
||||||
|
echo "❌ Bitte setzen Sie JWT_SECRET Umgebungsvariable"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Setze sichere Berechtigungen
|
||||||
|
chmod 600 /app/.env
|
||||||
|
|
||||||
|
echo "🔧 Starte Anwendung..."
|
||||||
|
exec "$@"
|
||||||
@@ -6,7 +6,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"react": "^19.0.0",
|
"react": "^19.0.0",
|
||||||
"react-dom": "^19.0.0",
|
"react-dom": "^19.0.0",
|
||||||
"react-router-dom": "^6.28.0"
|
"react-router-dom": "^6.28.0",
|
||||||
|
"date-fns": "4.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "20.19.23",
|
"@types/node": "20.19.23",
|
||||||
@@ -16,7 +17,9 @@
|
|||||||
"@vitejs/plugin-react": "^4.3.3",
|
"@vitejs/plugin-react": "^4.3.3",
|
||||||
"typescript": "^5.7.3",
|
"typescript": "^5.7.3",
|
||||||
"vite": "^6.0.7",
|
"vite": "^6.0.7",
|
||||||
"esbuild": "^0.21.0"
|
"esbuild": "^0.21.0",
|
||||||
|
"terser": "5.44.0",
|
||||||
|
"babel-plugin-transform-remove-console": "6.9.4"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// src/App.tsx - UPDATED FOR VITE
|
// src/App.tsx
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
|
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
|
||||||
import { AuthProvider, useAuth } from './contexts/AuthContext';
|
import { AuthProvider, useAuth } from './contexts/AuthContext';
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// frontend/src/components/Layout/Footer.tsx - ELEGANT WHITE DESIGN
|
// frontend/src/components/Layout/Footer.tsx
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
const Footer: React.FC = () => {
|
const Footer: React.FC = () => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// frontend/src/pages/About/About.tsx
|
// frontend/src/components/Layout/FooterLinks/About/About.tsx
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
const About: React.FC = () => {
|
const About: React.FC = () => {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// frontend/src/components/Layout/FooterLinks/CommunityLinks/communityLinks.tsx
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
export const CommunityContact: React.FC = () => (
|
export const CommunityContact: React.FC = () => (
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// frontend/src/pages/FAQ/FAQ.tsx
|
// frontend/src/components/Layout/FooterLinks/FAQ/FAQ.tsx
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
|
|
||||||
const FAQ: React.FC = () => {
|
const FAQ: React.FC = () => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// frontend/src/pages/Features/Features.tsx
|
// frontend/src/components/Layou/FooterLinks/Features/Features.tsx
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
const Features: React.FC = () => {
|
const Features: React.FC = () => {
|
||||||
|
|||||||
@@ -1,220 +0,0 @@
|
|||||||
/* Layout.css - Professionelles Design */
|
|
||||||
.layout {
|
|
||||||
min-height: 100vh;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Header */
|
|
||||||
.header {
|
|
||||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
||||||
color: white;
|
|
||||||
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
||||||
position: sticky;
|
|
||||||
top: 0;
|
|
||||||
z-index: 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
.header-content {
|
|
||||||
max-width: 1200px;
|
|
||||||
margin: 0 auto;
|
|
||||||
padding: 0 20px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
height: 70px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.logo h1 {
|
|
||||||
margin: 0;
|
|
||||||
font-size: 1.5rem;
|
|
||||||
font-weight: 700;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Desktop Navigation */
|
|
||||||
.desktop-nav {
|
|
||||||
display: flex;
|
|
||||||
gap: 2rem;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.nav-link {
|
|
||||||
color: white;
|
|
||||||
text-decoration: none;
|
|
||||||
padding: 0.5rem 1rem;
|
|
||||||
border-radius: 6px;
|
|
||||||
transition: all 0.3s ease;
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
|
|
||||||
.nav-link:hover {
|
|
||||||
background: rgba(255, 255, 255, 0.1);
|
|
||||||
transform: translateY(-1px);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* User Menu */
|
|
||||||
.user-menu {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.user-info {
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
|
|
||||||
.logout-btn {
|
|
||||||
background: rgba(255, 255, 255, 0.1);
|
|
||||||
color: white;
|
|
||||||
border: 1px solid rgba(255, 255, 255, 0.3);
|
|
||||||
padding: 0.5rem 1rem;
|
|
||||||
border-radius: 6px;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: all 0.3s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.logout-btn:hover {
|
|
||||||
background: rgba(255, 255, 255, 0.2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Mobile Menu Button */
|
|
||||||
.mobile-menu-btn {
|
|
||||||
display: none;
|
|
||||||
background: none;
|
|
||||||
border: none;
|
|
||||||
color: white;
|
|
||||||
font-size: 1.5rem;
|
|
||||||
cursor: pointer;
|
|
||||||
padding: 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Mobile Navigation */
|
|
||||||
.mobile-nav {
|
|
||||||
display: none;
|
|
||||||
flex-direction: column;
|
|
||||||
background: white;
|
|
||||||
padding: 1rem;
|
|
||||||
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.mobile-nav-link {
|
|
||||||
color: #333;
|
|
||||||
text-decoration: none;
|
|
||||||
padding: 1rem;
|
|
||||||
border-bottom: 1px solid #eee;
|
|
||||||
transition: background-color 0.3s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mobile-nav-link:hover {
|
|
||||||
background-color: #f5f5f5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mobile-user-info {
|
|
||||||
padding: 1rem;
|
|
||||||
border-top: 1px solid #eee;
|
|
||||||
margin-top: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mobile-logout-btn {
|
|
||||||
background: #667eea;
|
|
||||||
color: white;
|
|
||||||
border: none;
|
|
||||||
padding: 0.5rem 1rem;
|
|
||||||
border-radius: 6px;
|
|
||||||
cursor: pointer;
|
|
||||||
margin-top: 0.5rem;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Main Content */
|
|
||||||
.main-content {
|
|
||||||
flex: 1;
|
|
||||||
background-color: #f8f9fa;
|
|
||||||
min-height: calc(100vh - 140px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.content-container {
|
|
||||||
max-width: 1200px;
|
|
||||||
margin: 0 auto;
|
|
||||||
padding: 2rem 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Footer */
|
|
||||||
.footer {
|
|
||||||
background: #2c3e50;
|
|
||||||
color: white;
|
|
||||||
margin-top: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.footer-content {
|
|
||||||
max-width: 1200px;
|
|
||||||
margin: 0 auto;
|
|
||||||
padding: 2rem 20px;
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
|
|
||||||
gap: 2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.footer-section h3,
|
|
||||||
.footer-section h4 {
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
color: #ecf0f1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.footer-section a {
|
|
||||||
color: #bdc3c7;
|
|
||||||
text-decoration: none;
|
|
||||||
display: block;
|
|
||||||
margin-bottom: 0.5rem;
|
|
||||||
transition: color 0.3s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.footer-section a:hover {
|
|
||||||
color: #3498db;
|
|
||||||
}
|
|
||||||
|
|
||||||
.footer-bottom {
|
|
||||||
border-top: 1px solid #34495e;
|
|
||||||
padding: 1rem 20px;
|
|
||||||
text-align: center;
|
|
||||||
color: #95a5a6;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Responsive Design */
|
|
||||||
@media (max-width: 768px) {
|
|
||||||
.desktop-nav,
|
|
||||||
.user-menu {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mobile-menu-btn {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mobile-nav {
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
|
|
||||||
.header-content {
|
|
||||||
padding: 0 15px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.content-container {
|
|
||||||
padding: 1rem 15px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.footer-content {
|
|
||||||
grid-template-columns: 1fr;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 480px) {
|
|
||||||
.logo h1 {
|
|
||||||
font-size: 1.2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.content-container {
|
|
||||||
padding: 1rem 10px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// frontend/src/components/Layout/Layout.tsx - ELEGANT WHITE DESIGN
|
// frontend/src/components/Layout/Layout.tsx
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Navigation from './Navigation';
|
import Navigation from './Navigation';
|
||||||
import Footer from './Footer';
|
import Footer from './Footer';
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// frontend/src/components/Layout/Navigation.tsx - ELEGANT WHITE DESIGN
|
// frontend/src/components/Layout/Navigation.tsx
|
||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { useAuth } from '../../contexts/AuthContext';
|
import { useAuth } from '../../contexts/AuthContext';
|
||||||
import PillNav from '../PillNav/PillNav';
|
import PillNav from '../PillNav/PillNav';
|
||||||
|
|||||||
@@ -1,88 +0,0 @@
|
|||||||
/* frontend/src/components/PillNav/PillNav.module.css */
|
|
||||||
.pillNavContainer {
|
|
||||||
display: flex;
|
|
||||||
gap: 8px;
|
|
||||||
overflow-x: auto;
|
|
||||||
padding: 4px;
|
|
||||||
scrollbar-width: none;
|
|
||||||
-ms-overflow-style: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pillNavContainer::-webkit-scrollbar {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pill {
|
|
||||||
padding: 8px 16px;
|
|
||||||
border-radius: 9999px;
|
|
||||||
border: 1px solid;
|
|
||||||
font-size: 14px;
|
|
||||||
font-weight: 500;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: all 0.2s ease-in-out;
|
|
||||||
white-space: nowrap;
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pill:focus-visible {
|
|
||||||
outline: 2px solid #3b82f6;
|
|
||||||
outline-offset: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Solid Variant */
|
|
||||||
.pillSolid {
|
|
||||||
background-color: transparent;
|
|
||||||
color: #6b7280;
|
|
||||||
border-color: #d1d5db;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pillSolidActive {
|
|
||||||
background-color: #2563eb;
|
|
||||||
color: white;
|
|
||||||
border-color: #2563eb;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pillSolid:hover:not(.pillSolidActive) {
|
|
||||||
background-color: #f3f4f6;
|
|
||||||
color: #374151;
|
|
||||||
border-color: #9ca3af;
|
|
||||||
transform: translateY(-1px);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Outline Variant */
|
|
||||||
.pillOutline {
|
|
||||||
background-color: transparent;
|
|
||||||
color: #6b7280;
|
|
||||||
border-color: #d1d5db;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pillOutlineActive {
|
|
||||||
color: #2563eb;
|
|
||||||
border-color: #2563eb;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pillOutline:hover:not(.pillOutlineActive) {
|
|
||||||
background-color: #f3f4f6;
|
|
||||||
color: #374151;
|
|
||||||
border-color: #9ca3af;
|
|
||||||
transform: translateY(-1px);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Ghost Variant */
|
|
||||||
.pillGhost {
|
|
||||||
background-color: transparent;
|
|
||||||
color: #6b7280;
|
|
||||||
border-color: transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pillGhostActive {
|
|
||||||
background-color: #f3f4f6;
|
|
||||||
color: #111827;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pillGhost:hover:not(.pillGhostActive) {
|
|
||||||
background-color: #f9fafb;
|
|
||||||
color: #374151;
|
|
||||||
transform: translateY(-1px);
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// frontend/src/components/PillNav/PillNav.tsx - ELEGANT WHITE DESIGN
|
// frontend/src/components/PillNav/PillNav.tsx
|
||||||
import React, { useEffect, useRef } from 'react';
|
import React, { useEffect, useRef } from 'react';
|
||||||
|
|
||||||
export interface PillNavItem {
|
export interface PillNavItem {
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
// frontend/src/components/PillNav/index.ts
|
|
||||||
export { default } from './PillNav';
|
|
||||||
export type { PillNavProps, PillNavItem } from './PillNav';
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// frontend/src/design/DesignSystem.tsx
|
// frontend/src/design/DesignSystem.txt
|
||||||
export const designTokens = {
|
export const designTokens = {
|
||||||
colors: {
|
colors: {
|
||||||
// Primary Colors
|
// Primary Colors
|
||||||
@@ -185,7 +185,7 @@ const EmployeeForm: React.FC<EmployeeFormProps> = ({
|
|||||||
// Password change logic remains the same
|
// Password change logic remains the same
|
||||||
if (showPasswordSection && passwordForm.newPassword && hasRole(['admin'])) {
|
if (showPasswordSection && passwordForm.newPassword && hasRole(['admin'])) {
|
||||||
if (passwordForm.newPassword.length < 6) {
|
if (passwordForm.newPassword.length < 6) {
|
||||||
throw new Error('Das neue Passwort muss mindestens 6 Zeichen lang sein');
|
throw new Error('Das Passwort muss mindestens 6 Zeichen lang sein, Zahlen und Groß- / Kleinbuchstaben enthalten');
|
||||||
}
|
}
|
||||||
if (passwordForm.newPassword !== passwordForm.confirmPassword) {
|
if (passwordForm.newPassword !== passwordForm.confirmPassword) {
|
||||||
throw new Error('Die Passwörter stimmen nicht überein');
|
throw new Error('Die Passwörter stimmen nicht überein');
|
||||||
@@ -351,10 +351,10 @@ const EmployeeForm: React.FC<EmployeeFormProps> = ({
|
|||||||
borderRadius: '4px',
|
borderRadius: '4px',
|
||||||
fontSize: '16px'
|
fontSize: '16px'
|
||||||
}}
|
}}
|
||||||
placeholder="Mindestens 6 Zeichen"
|
placeholder="Mindestens 6 Zeichen, Zahlen, Groß- / Kleinzeichen"
|
||||||
/>
|
/>
|
||||||
<div style={{ fontSize: '12px', color: '#7f8c8d', marginTop: '5px' }}>
|
<div style={{ fontSize: '12px', color: '#7f8c8d', marginTop: '5px' }}>
|
||||||
Das Passwort muss mindestens 6 Zeichen lang sein.
|
Das Passwort muss mindestens 6 Zeichen lang sein, Zahlen und Groß- / Kleinbuchstaben enthalten.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -672,7 +672,7 @@ const EmployeeForm: React.FC<EmployeeFormProps> = ({
|
|||||||
borderRadius: '4px',
|
borderRadius: '4px',
|
||||||
fontSize: '16px'
|
fontSize: '16px'
|
||||||
}}
|
}}
|
||||||
placeholder="Mindestens 6 Zeichen"
|
placeholder="Mindestens 6 Zeichen, Zahlen, Groß- / Kleinzeichen"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -333,7 +333,7 @@ const Setup: React.FC = () => {
|
|||||||
disabled={loading}
|
disabled={loading}
|
||||||
style={{
|
style={{
|
||||||
padding: '0.75rem 2rem',
|
padding: '0.75rem 2rem',
|
||||||
backgroundColor: loading ? '#6c757d' : '#007bff',
|
backgroundColor: loading ? '#6c757d' : '#51258f',
|
||||||
color: 'white',
|
color: 'white',
|
||||||
border: 'none',
|
border: 'none',
|
||||||
borderRadius: '6px',
|
borderRadius: '6px',
|
||||||
|
|||||||
@@ -107,7 +107,7 @@
|
|||||||
|
|
||||||
.createButton {
|
.createButton {
|
||||||
padding: 10px 20px;
|
padding: 10px 20px;
|
||||||
background-color: #2ecc71;
|
background-color: #51258f;
|
||||||
color: white;
|
color: white;
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
@@ -116,7 +116,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.createButton:hover {
|
.createButton:hover {
|
||||||
background-color: #27ae60;
|
background-color: #51258f;
|
||||||
}
|
}
|
||||||
|
|
||||||
.createButton:disabled {
|
.createButton:disabled {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// frontend/src/services/shiftPlanService.ts
|
// frontend/src/services/shiftPlanService.ts
|
||||||
import { authService } from './authService';
|
import { authService } from './authService';
|
||||||
import { ShiftPlan, CreateShiftPlanRequest, ScheduledShift, CreateShiftFromTemplateRequest } from '../models/ShiftPlan';
|
import { ShiftPlan, CreateShiftPlanRequest } from '../models/ShiftPlan';
|
||||||
import { TEMPLATE_PRESETS } from '../models/defaults/shiftPlanDefaults';
|
import { TEMPLATE_PRESETS } from '../models/defaults/shiftPlanDefaults';
|
||||||
|
|
||||||
const API_BASE_URL = '/api/shift-plans';
|
const API_BASE_URL = '/api/shift-plans';
|
||||||
|
|||||||
@@ -1,14 +1,29 @@
|
|||||||
import { defineConfig } from 'vite'
|
// vite.config.ts
|
||||||
|
import { defineConfig, loadEnv } from 'vite'
|
||||||
import react from '@vitejs/plugin-react'
|
import react from '@vitejs/plugin-react'
|
||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
export default defineConfig(({ mode }) => {
|
||||||
export default defineConfig({
|
const isProduction = mode === 'production'
|
||||||
|
const isDevelopment = mode === 'development'
|
||||||
|
|
||||||
|
const env = loadEnv(mode, process.cwd(), '')
|
||||||
|
|
||||||
|
// 🆕 WICHTIG: Relative Pfade für Production
|
||||||
|
const clientEnv = {
|
||||||
|
NODE_ENV: mode,
|
||||||
|
ENABLE_PRO: env.ENABLE_PRO || 'false',
|
||||||
|
VITE_APP_TITLE: env.APP_TITLE || 'Shift Planning App',
|
||||||
|
VITE_API_URL: isProduction ? '/api' : 'http://localhost:3002/api',
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
|
|
||||||
server: {
|
server: {
|
||||||
port: 3003,
|
port: 3003,
|
||||||
host: true,
|
host: true,
|
||||||
open: true,
|
open: isDevelopment,
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api': {
|
'/api': {
|
||||||
target: 'http://localhost:3002',
|
target: 'http://localhost:3002',
|
||||||
@@ -17,15 +32,28 @@ export default defineConfig({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
build: {
|
build: {
|
||||||
outDir: 'dist',
|
outDir: 'dist',
|
||||||
sourcemap: true,
|
sourcemap: isDevelopment,
|
||||||
|
base: isProduction ? '/' : '/',
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
input: {
|
output: {
|
||||||
main: resolve(__dirname, 'index.html')
|
chunkFileNames: 'assets/[name]-[hash].js',
|
||||||
}
|
entryFileNames: 'assets/[name]-[hash].js',
|
||||||
|
assetFileNames: 'assets/[name]-[hash].[ext]',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
minify: isProduction ? 'terser' : false,
|
||||||
|
terserOptions: isProduction ? {
|
||||||
|
compress: {
|
||||||
|
drop_console: true,
|
||||||
|
drop_debugger: true,
|
||||||
|
pure_funcs: ['console.log', 'console.debug', 'console.info']
|
||||||
|
}
|
||||||
|
} : undefined,
|
||||||
|
},
|
||||||
|
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': resolve(__dirname, './src'),
|
'@': resolve(__dirname, './src'),
|
||||||
@@ -38,8 +66,10 @@ export default defineConfig({
|
|||||||
'@/design': resolve(__dirname, './src/design')
|
'@/design': resolve(__dirname, './src/design')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// Define environment variables
|
|
||||||
define: {
|
define: Object.keys(clientEnv).reduce((acc, key) => {
|
||||||
'process.env': process.env
|
acc[`import.meta.env.${key}`] = JSON.stringify(clientEnv[key])
|
||||||
|
return acc
|
||||||
|
}, {} as Record<string, string>)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
1677
package-lock.json
generated
1677
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user