- product_types 참조 테이블 + projects.product_type_id FK (tkuser 마이그레이션) - schedule_entries에 work_type_id, risk_assessment_id, source 컬럼 추가 - schedule_phases에 product_type_id 추가 (phase 오염 방지) - generateFromTemplate: tksafety 템플릿 기반 공정 자동 생성 (트랜잭션) - phase 매칭 3단계 우선순위 (전용→범용→신규) - 간트 데이터 NULL 날짜 guard 추가 - system1 startup 마이그레이션 러너 추가 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
93 lines
2.4 KiB
JavaScript
93 lines
2.4 KiB
JavaScript
/**
|
|
* Project Controller
|
|
*
|
|
* 프로젝트 CRUD
|
|
*/
|
|
|
|
const projectModel = require('../models/projectModel');
|
|
|
|
async function getAll(req, res, next) {
|
|
try {
|
|
const projects = await projectModel.getAll();
|
|
res.json({ success: true, data: projects });
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
}
|
|
|
|
async function getActive(req, res, next) {
|
|
try {
|
|
const projects = await projectModel.getActive();
|
|
res.json({ success: true, data: projects });
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
}
|
|
|
|
async function getById(req, res, next) {
|
|
try {
|
|
const project = await projectModel.getById(parseInt(req.params.id));
|
|
if (!project) {
|
|
return res.status(404).json({ success: false, error: '프로젝트를 찾을 수 없습니다' });
|
|
}
|
|
res.json({ success: true, data: project });
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
}
|
|
|
|
async function create(req, res, next) {
|
|
try {
|
|
const { job_no, project_name } = req.body;
|
|
|
|
if (!job_no || !project_name) {
|
|
return res.status(400).json({ success: false, error: 'Job No와 프로젝트명은 필수입니다' });
|
|
}
|
|
|
|
const project = await projectModel.create(req.body);
|
|
res.status(201).json({ success: true, data: project });
|
|
} catch (err) {
|
|
if (err.code === 'ER_DUP_ENTRY') {
|
|
return res.status(409).json({ success: false, error: '이미 존재하는 Job No입니다' });
|
|
}
|
|
next(err);
|
|
}
|
|
}
|
|
|
|
async function update(req, res, next) {
|
|
try {
|
|
const id = parseInt(req.params.id);
|
|
const project = await projectModel.update(id, req.body);
|
|
if (!project) {
|
|
return res.status(404).json({ success: false, error: '프로젝트를 찾을 수 없습니다' });
|
|
}
|
|
res.json({ success: true, data: project });
|
|
} catch (err) {
|
|
if (err.code === 'ER_DUP_ENTRY') {
|
|
return res.status(409).json({ success: false, error: '이미 존재하는 Job No입니다' });
|
|
}
|
|
next(err);
|
|
}
|
|
}
|
|
|
|
async function remove(req, res, next) {
|
|
try {
|
|
const id = parseInt(req.params.id);
|
|
await projectModel.deactivate(id);
|
|
res.json({ success: true, message: '프로젝트가 비활성화되었습니다' });
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
}
|
|
|
|
async function getProductTypes(req, res, next) {
|
|
try {
|
|
const types = await projectModel.getProductTypes();
|
|
res.json({ success: true, data: types });
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
}
|
|
|
|
module.exports = { getAll, getActive, getById, create, update, remove, getProductTypes };
|