mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-12-01 06:55:45 +01:00
Compare commits
12 Commits
v0.0.5
...
f5aa376e31
| Author | SHA1 | Date | |
|---|---|---|---|
| f5aa376e31 | |||
| e82e584f76 | |||
| e177c3d2a6 | |||
| de23ea00ee | |||
| d78ba474d8 | |||
| 5c7786bc19 | |||
| 15107cdc63 | |||
| 22266c765b | |||
| a66609a40c | |||
| 87dda38bc3 | |||
| 9de501c7eb | |||
| 5c6a50ddcf |
13
Dockerfile
13
Dockerfile
@@ -49,7 +49,7 @@ COPY frontend/public/ ./public/
|
|||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Production stage
|
# Production stage
|
||||||
FROM node:20-alpine
|
FROM node:20-bookworm
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
@@ -70,16 +70,19 @@ COPY --from=frontend-builder /app/frontend/build/ ./frontend-build/
|
|||||||
# Copy PM2 configuration
|
# Copy PM2 configuration
|
||||||
COPY ecosystem.config.cjs ./
|
COPY ecosystem.config.cjs ./
|
||||||
|
|
||||||
# Create a non-root user and group
|
# Create a non-root user and group - DEBIAN STYLE
|
||||||
RUN addgroup -g 1001 -S nodejs && \
|
RUN groupadd -g 1001 nodejs && \
|
||||||
adduser -S schichtplan -u 1001 -G nodejs && \
|
useradd -m -u 1001 -s /bin/bash -g nodejs schichtplan && \
|
||||||
chown -R schichtplan:nodejs /app && \
|
chown -R schichtplan:nodejs /app && \
|
||||||
chmod 755 /app && \
|
chmod 755 /app && \
|
||||||
chmod 775 /app/data
|
chmod 775 /app/data
|
||||||
|
|
||||||
|
# Set PM2 to use app directory instead of home directory
|
||||||
|
ENV PM2_HOME=/app/.pm2
|
||||||
|
|
||||||
USER schichtplan
|
USER schichtplan
|
||||||
|
|
||||||
EXPOSE 3000 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
|
||||||
|
|||||||
@@ -8,7 +8,30 @@ const __filename = fileURLToPath(import.meta.url);
|
|||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
export async function initializeDatabase(): Promise<void> {
|
export async function initializeDatabase(): Promise<void> {
|
||||||
const schemaPath = path.join(__dirname, '../database/schema.sql');
|
const possiblePaths = [
|
||||||
|
path.join(__dirname, '../database/schema.sql'),
|
||||||
|
path.join(__dirname, '../../database/schema.sql'),
|
||||||
|
path.join(process.cwd(), 'database/schema.sql'),
|
||||||
|
path.join(process.cwd(), 'src/database/schema.sql'),
|
||||||
|
path.join(process.cwd(), 'dist/database/schema.sql')
|
||||||
|
];
|
||||||
|
|
||||||
|
let schemaPath: string | null = null;
|
||||||
|
|
||||||
|
for (const p of possiblePaths) {
|
||||||
|
if (fs.existsSync(p)) {
|
||||||
|
schemaPath = p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!schemaPath) {
|
||||||
|
throw new Error(
|
||||||
|
`❌ schema.sql not found in any of the tested paths:\n${possiblePaths.join('\n')}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`✅ Using schema at: ${schemaPath}`);
|
||||||
const schema = fs.readFileSync(schemaPath, 'utf8');
|
const schema = fs.readFileSync(schemaPath, 'utf8');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
// backend/src/server.ts
|
// backend/src/server.ts
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import cors from 'cors';
|
import path from 'path';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
import { initializeDatabase } from './scripts/initializeDatabase.js';
|
import { initializeDatabase } from './scripts/initializeDatabase.js';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
// Route imports
|
// Route imports
|
||||||
import authRoutes from './routes/auth.js';
|
import authRoutes from './routes/auth.js';
|
||||||
@@ -11,11 +13,13 @@ 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';
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = 3002;
|
const PORT = 3002;
|
||||||
|
|
||||||
// CORS und Middleware
|
// Middleware
|
||||||
app.use(cors());
|
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
// API Routes
|
// API Routes
|
||||||
@@ -26,17 +30,6 @@ 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);
|
||||||
|
|
||||||
// Error handling middleware should come after routes
|
|
||||||
app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
||||||
console.error('Unhandled error:', err);
|
|
||||||
res.status(500).json({ error: 'Internal server error' });
|
|
||||||
});
|
|
||||||
|
|
||||||
// 404 handler for API routes
|
|
||||||
app.use('/api/*', (req, res) => {
|
|
||||||
res.status(404).json({ error: 'API endpoint not found' });
|
|
||||||
});
|
|
||||||
|
|
||||||
// Health route
|
// Health route
|
||||||
app.get('/api/health', (req: any, res: any) => {
|
app.get('/api/health', (req: any, res: any) => {
|
||||||
res.json({
|
res.json({
|
||||||
@@ -46,49 +39,82 @@ app.get('/api/health', (req: any, res: any) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Setup status route (additional endpoint for clarity)
|
// 🆕 STATIC FILE SERVING FÜR FRONTEND
|
||||||
app.get('/api/initial-setup', async (req: any, res: any) => {
|
const frontendBuildPath = path.join(__dirname, '../frontend-build');
|
||||||
try {
|
console.log('📁 Frontend build path:', frontendBuildPath);
|
||||||
const { db } = await import('./services/databaseService.js');
|
|
||||||
|
|
||||||
const adminExists = await db.get<{ 'COUNT(*)': number }>(
|
|
||||||
'SELECT COUNT(*) FROM employees WHERE role = ?',
|
|
||||||
['admin']
|
|
||||||
);
|
|
||||||
|
|
||||||
res.json({
|
// Überprüfe ob das Verzeichnis existiert
|
||||||
needsInitialSetup: !adminExists || adminExists['COUNT(*)'] === 0
|
if (fs.existsSync(frontendBuildPath)) {
|
||||||
});
|
console.log('✅ Frontend build directory exists');
|
||||||
} catch (error) {
|
const files = fs.readdirSync(frontendBuildPath);
|
||||||
console.error('Error checking initial setup:', error);
|
console.log('📄 Files in frontend-build:', files);
|
||||||
res.status(500).json({ error: 'Internal server error' });
|
|
||||||
|
// Serviere statische Dateien
|
||||||
|
app.use(express.static(frontendBuildPath));
|
||||||
|
|
||||||
|
console.log('✅ Static file serving configured');
|
||||||
|
} else {
|
||||||
|
console.log('❌ Frontend build directory NOT FOUND:', frontendBuildPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
app.get('/', (req, res) => {
|
||||||
|
const indexPath = path.join(frontendBuildPath, 'index.html');
|
||||||
|
console.log('📄 Serving index.html from:', indexPath);
|
||||||
|
|
||||||
|
if (fs.existsSync(indexPath)) {
|
||||||
|
res.sendFile(indexPath);
|
||||||
|
} else {
|
||||||
|
console.error('❌ index.html not found at:', indexPath);
|
||||||
|
res.status(404).send('Frontend not found - index.html missing');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('*', (req, res) => {
|
||||||
|
// Ignoriere API Routes
|
||||||
|
if (req.path.startsWith('/api/')) {
|
||||||
|
return res.status(404).json({ error: 'API endpoint not found' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const indexPath = path.join(frontendBuildPath, 'index.html');
|
||||||
|
console.log('🔄 Client-side routing for:', req.path, '-> index.html');
|
||||||
|
|
||||||
|
if (fs.existsSync(indexPath)) {
|
||||||
|
res.sendFile(indexPath);
|
||||||
|
} else {
|
||||||
|
console.error('❌ index.html not found for client-side routing');
|
||||||
|
res.status(404).json({ error: 'Frontend application not found' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Error handling middleware
|
||||||
|
app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
|
console.error('Unhandled error:', err);
|
||||||
|
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
|
// Initialize database with base schema
|
||||||
await initializeDatabase();
|
await initializeDatabase();
|
||||||
//console.log('✅ Database initialized successfully');
|
|
||||||
|
|
||||||
// Apply any pending migrations
|
// Apply any pending migrations
|
||||||
const { applyMigration } = await import('./scripts/applyMigration.js');
|
const { applyMigration } = await import('./scripts/applyMigration.js');
|
||||||
await applyMigration();
|
await applyMigration();
|
||||||
//console.log('✅ Database migrations applied');
|
|
||||||
|
|
||||||
// Start server only after successful initialization
|
// Start server only after successful initialization
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
console.log('🎉 BACKEND STARTED SUCCESSFULLY!');
|
console.log('🎉 APPLICATION STARTED SUCCESSFULLY!');
|
||||||
console.log(`📍 Port: ${PORT}`);
|
console.log(`📍 Port: ${PORT}`);
|
||||||
console.log(`📍 Health: http://localhost:${PORT}/api/health`);
|
console.log(`📍 Frontend: http://localhost:${PORT}`);
|
||||||
|
console.log(`📍 API: http://localhost:${PORT}/api`);
|
||||||
console.log('');
|
console.log('');
|
||||||
console.log(`🔧 Setup ready at: http://localhost:${PORT}/api/setup/status`);
|
console.log(`🔧 Setup: http://localhost:${PORT}/api/setup/status`);
|
||||||
console.log('📝 Create your admin account on first launch');
|
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);
|
||||||
process.exit(1); // Exit if initialization fails
|
process.exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
apps: [
|
apps: [
|
||||||
{
|
{
|
||||||
name: 'backend',
|
name: 'schichtplaner',
|
||||||
script: './dist/server.js',
|
script: './dist/server.js',
|
||||||
instances: 1,
|
instances: 1,
|
||||||
exec_mode: 'fork',
|
exec_mode: 'fork',
|
||||||
@@ -10,21 +10,8 @@ module.exports = {
|
|||||||
NODE_ENV: 'production',
|
NODE_ENV: 'production',
|
||||||
PORT: 3002
|
PORT: 3002
|
||||||
},
|
},
|
||||||
error_file: './logs/backend-err.log',
|
error_file: './logs/app-err.log',
|
||||||
out_file: './logs/backend-out.log',
|
out_file: './logs/app-out.log',
|
||||||
time: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'frontend',
|
|
||||||
script: 'npx',
|
|
||||||
args: 'serve -s frontend-build -l 3000',
|
|
||||||
instances: 1,
|
|
||||||
exec_mode: 'fork',
|
|
||||||
env: {
|
|
||||||
NODE_ENV: 'production'
|
|
||||||
},
|
|
||||||
error_file: './logs/frontend-err.log',
|
|
||||||
out_file: './logs/frontend-out.log',
|
|
||||||
time: true
|
time: true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ interface AuthContextType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
||||||
|
const API_BASE_URL = process.env.REACT_APP_API_BASE_URL || '/api';
|
||||||
|
|
||||||
interface AuthProviderProps {
|
interface AuthProviderProps {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
@@ -48,7 +49,7 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
|
|||||||
const checkSetupStatus = async (): Promise<void> => {
|
const checkSetupStatus = async (): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
console.log('🔍 Checking setup status...');
|
console.log('🔍 Checking setup status...');
|
||||||
const response = await fetch('http://localhost:3002/api/setup/status');
|
const response = await fetch(`${API_BASE_URL}/setup/status`);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Setup status check failed');
|
throw new Error('Setup status check failed');
|
||||||
}
|
}
|
||||||
@@ -72,7 +73,7 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch('http://localhost:3002/api/auth/me', {
|
const response = await fetch(`${API_BASE_URL}/auth/me`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${token}`
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
@@ -104,7 +105,7 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
|
|||||||
try {
|
try {
|
||||||
console.log('🔐 Attempting login for:', credentials.email);
|
console.log('🔐 Attempting login for:', credentials.email);
|
||||||
|
|
||||||
const response = await fetch('http://localhost:3002/api/auth/login', {
|
const response = await fetch(`${API_BASE_URL}/auth/login`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { useAuth } from '../../contexts/AuthContext';
|
import { useAuth } from '../../contexts/AuthContext';
|
||||||
|
|
||||||
|
const API_BASE_URL = '/api';
|
||||||
|
|
||||||
const Setup: React.FC = () => {
|
const Setup: React.FC = () => {
|
||||||
const [step, setStep] = useState(1);
|
const [step, setStep] = useState(1);
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
@@ -73,7 +75,7 @@ const Setup: React.FC = () => {
|
|||||||
|
|
||||||
console.log('🚀 Sending setup request...', payload);
|
console.log('🚀 Sending setup request...', payload);
|
||||||
|
|
||||||
const response = await fetch('http://localhost:3002/api/setup/admin', {
|
const response = await fetch(`${API_BASE_URL}/setup/admin`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// frontend/src/services/authService.ts
|
// frontend/src/services/authService.ts
|
||||||
import { Employee } from '../models/Employee';
|
import { Employee } from '../models/Employee';
|
||||||
const API_BASE = 'http://localhost:3002/api';
|
const API_BASE = process.env.REACT_APP_API_BASE_URL || '/api';
|
||||||
|
|
||||||
export interface LoginRequest {
|
export interface LoginRequest {
|
||||||
email: string;
|
email: string;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// frontend/src/services/employeeService.ts
|
// frontend/src/services/employeeService.ts
|
||||||
import { Employee, CreateEmployeeRequest, UpdateEmployeeRequest, EmployeeAvailability } from '../models/Employee';
|
import { Employee, CreateEmployeeRequest, UpdateEmployeeRequest, EmployeeAvailability } from '../models/Employee';
|
||||||
|
|
||||||
const API_BASE_URL = 'http://localhost:3002/api';
|
const API_BASE_URL = '/api';
|
||||||
|
|
||||||
const getAuthHeaders = () => {
|
const getAuthHeaders = () => {
|
||||||
const token = localStorage.getItem('token');
|
const token = localStorage.getItem('token');
|
||||||
|
|||||||
@@ -4,9 +4,7 @@ import { Employee, EmployeeAvailability } from '../models/Employee';
|
|||||||
import { authService } from './authService';
|
import { authService } from './authService';
|
||||||
import { AssignmentResult, ScheduleRequest } from '../models/scheduling';
|
import { AssignmentResult, ScheduleRequest } from '../models/scheduling';
|
||||||
|
|
||||||
const API_BASE_URL = 'http://localhost:3002/api';
|
const API_BASE_URL = '/api';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Helper function to get auth headers
|
// Helper function to get auth headers
|
||||||
const getAuthHeaders = () => {
|
const getAuthHeaders = () => {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { authService } from './authService';
|
|||||||
import { ShiftPlan, CreateShiftPlanRequest, ScheduledShift, CreateShiftFromTemplateRequest } from '../models/ShiftPlan';
|
import { ShiftPlan, CreateShiftPlanRequest, ScheduledShift, CreateShiftFromTemplateRequest } from '../models/ShiftPlan';
|
||||||
import { TEMPLATE_PRESETS } from '../models/defaults/shiftPlanDefaults';
|
import { TEMPLATE_PRESETS } from '../models/defaults/shiftPlanDefaults';
|
||||||
|
|
||||||
const API_BASE = 'http://localhost:3002/api/shift-plans';
|
const API_BASE_URL = '/api/shift-plans';
|
||||||
|
|
||||||
// Helper function to get auth headers
|
// Helper function to get auth headers
|
||||||
const getAuthHeaders = () => {
|
const getAuthHeaders = () => {
|
||||||
@@ -25,7 +25,7 @@ const handleResponse = async (response: Response) => {
|
|||||||
|
|
||||||
export const shiftPlanService = {
|
export const shiftPlanService = {
|
||||||
async getShiftPlans(): Promise<ShiftPlan[]> {
|
async getShiftPlans(): Promise<ShiftPlan[]> {
|
||||||
const response = await fetch(API_BASE, {
|
const response = await fetch(API_BASE_URL, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
...authService.getAuthHeaders()
|
...authService.getAuthHeaders()
|
||||||
@@ -50,7 +50,7 @@ export const shiftPlanService = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async getShiftPlan(id: string): Promise<ShiftPlan> {
|
async getShiftPlan(id: string): Promise<ShiftPlan> {
|
||||||
const response = await fetch(`${API_BASE}/${id}`, {
|
const response = await fetch(`${API_BASE_URL}/${id}`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
...authService.getAuthHeaders()
|
...authService.getAuthHeaders()
|
||||||
@@ -69,7 +69,7 @@ export const shiftPlanService = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async createShiftPlan(plan: CreateShiftPlanRequest): Promise<ShiftPlan> {
|
async createShiftPlan(plan: CreateShiftPlanRequest): Promise<ShiftPlan> {
|
||||||
const response = await fetch(API_BASE, {
|
const response = await fetch(API_BASE_URL, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -90,7 +90,7 @@ export const shiftPlanService = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async updateShiftPlan(id: string, plan: Partial<ShiftPlan>): Promise<ShiftPlan> {
|
async updateShiftPlan(id: string, plan: Partial<ShiftPlan>): Promise<ShiftPlan> {
|
||||||
const response = await fetch(`${API_BASE}/${id}`, {
|
const response = await fetch(`${API_BASE_URL}/${id}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -111,7 +111,7 @@ export const shiftPlanService = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async deleteShiftPlan(id: string): Promise<void> {
|
async deleteShiftPlan(id: string): Promise<void> {
|
||||||
const response = await fetch(`${API_BASE}/${id}`, {
|
const response = await fetch(`${API_BASE_URL}/${id}`, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -130,7 +130,7 @@ export const shiftPlanService = {
|
|||||||
|
|
||||||
// Get specific template or plan
|
// Get specific template or plan
|
||||||
getTemplate: async (id: string): Promise<ShiftPlan> => {
|
getTemplate: async (id: string): Promise<ShiftPlan> => {
|
||||||
const response = await fetch(`${API_BASE}/${id}`, {
|
const response = await fetch(`${API_BASE_URL}/${id}`, {
|
||||||
headers: getAuthHeaders()
|
headers: getAuthHeaders()
|
||||||
});
|
});
|
||||||
return handleResponse(response);
|
return handleResponse(response);
|
||||||
@@ -142,7 +142,7 @@ export const shiftPlanService = {
|
|||||||
console.log('🔄 Attempting to regenerate scheduled shifts...');
|
console.log('🔄 Attempting to regenerate scheduled shifts...');
|
||||||
|
|
||||||
// You'll need to add this API endpoint to your backend
|
// You'll need to add this API endpoint to your backend
|
||||||
const response = await fetch(`${API_BASE}/${planId}/regenerate-shifts`, {
|
const response = await fetch(`${API_BASE_URL}/${planId}/regenerate-shifts`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -162,7 +162,7 @@ export const shiftPlanService = {
|
|||||||
|
|
||||||
// Create new plan
|
// Create new plan
|
||||||
createPlan: async (data: CreateShiftPlanRequest): Promise<ShiftPlan> => {
|
createPlan: async (data: CreateShiftPlanRequest): Promise<ShiftPlan> => {
|
||||||
const response = await fetch(`${API_BASE}`, {
|
const response = await fetch(`${API_BASE_URL}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: getAuthHeaders(),
|
headers: getAuthHeaders(),
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
@@ -177,7 +177,7 @@ export const shiftPlanService = {
|
|||||||
endDate: string;
|
endDate: string;
|
||||||
isTemplate?: boolean;
|
isTemplate?: boolean;
|
||||||
}): Promise<ShiftPlan> => {
|
}): Promise<ShiftPlan> => {
|
||||||
const response = await fetch(`${API_BASE}/from-preset`, {
|
const response = await fetch(`${API_BASE_URL}/from-preset`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: getAuthHeaders(),
|
headers: getAuthHeaders(),
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
@@ -204,7 +204,7 @@ export const shiftPlanService = {
|
|||||||
try {
|
try {
|
||||||
console.log('🔄 Clearing assignments for plan:', planId);
|
console.log('🔄 Clearing assignments for plan:', planId);
|
||||||
|
|
||||||
const response = await fetch(`${API_BASE}/${planId}/clear-assignments`, {
|
const response = await fetch(`${API_BASE_URL}/${planId}/clear-assignments`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
Reference in New Issue
Block a user