- partner_schedules: work_date → start_date/end_date 기간 기반으로 변경 - project_id 컬럼 추가 (projects 테이블 연결, 선택사항) - 프로젝트 조회 API 추가 (GET /projects/active) - 일정 조회 시 기간 겹침 조건으로 필터링 - 체크인 시 기간 내 검증 추가 - 프론트엔드: 시작일/종료일 입력 + 프로젝트 선택 드롭다운 - 마이그레이션 SQL 포함 (scripts/migration-schedule-daterange.sql) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
68 lines
2.1 KiB
JavaScript
68 lines
2.1 KiB
JavaScript
const express = require('express');
|
|
const cors = require('cors');
|
|
const cron = require('node-cron');
|
|
const partnerRoutes = require('./routes/partnerRoutes');
|
|
const dayLaborRoutes = require('./routes/dayLaborRoutes');
|
|
const scheduleRoutes = require('./routes/scheduleRoutes');
|
|
const checkinRoutes = require('./routes/checkinRoutes');
|
|
const workReportRoutes = require('./routes/workReportRoutes');
|
|
const partnerAccountRoutes = require('./routes/partnerAccountRoutes');
|
|
const projectRoutes = require('./routes/projectRoutes');
|
|
|
|
const app = express();
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
const allowedOrigins = [
|
|
'https://tkfb.technicalkorea.net',
|
|
'https://tkreport.technicalkorea.net',
|
|
'https://tkqc.technicalkorea.net',
|
|
'https://tkuser.technicalkorea.net',
|
|
'https://tkpurchase.technicalkorea.net',
|
|
'https://tksafety.technicalkorea.net',
|
|
];
|
|
if (process.env.NODE_ENV === 'development') {
|
|
allowedOrigins.push('http://localhost:30080', 'http://localhost:30480');
|
|
}
|
|
app.use(cors({
|
|
origin: function(origin, cb) {
|
|
if (!origin || allowedOrigins.includes(origin) || /^http:\/\/192\.168\.\d+\.\d+(:\d+)?$/.test(origin)) return cb(null, true);
|
|
cb(new Error('CORS blocked: ' + origin));
|
|
},
|
|
credentials: true
|
|
}));
|
|
app.use(express.json());
|
|
|
|
// Health check
|
|
app.get('/health', (req, res) => {
|
|
res.json({ status: 'ok', service: 'tkpurchase-api', timestamp: new Date().toISOString() });
|
|
});
|
|
|
|
// Routes
|
|
app.use('/api/partners', partnerRoutes);
|
|
app.use('/api/day-labor', dayLaborRoutes);
|
|
app.use('/api/schedules', scheduleRoutes);
|
|
app.use('/api/checkins', checkinRoutes);
|
|
app.use('/api/work-reports', workReportRoutes);
|
|
app.use('/api/partner-accounts', partnerAccountRoutes);
|
|
app.use('/api/projects', projectRoutes);
|
|
|
|
// 404
|
|
app.use((req, res) => {
|
|
res.status(404).json({ success: false, error: 'Not Found' });
|
|
});
|
|
|
|
// Error handler
|
|
app.use((err, req, res, next) => {
|
|
console.error('tkpurchase-api Error:', err.message);
|
|
res.status(err.status || 500).json({
|
|
success: false,
|
|
error: err.message || 'Internal Server Error'
|
|
});
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`tkpurchase-api running on port ${PORT}`);
|
|
});
|
|
|
|
module.exports = app;
|