refactor: TBM/작업보고 코드 통합 및 API 쿼리 버그 수정
- 공통 유틸리티 추출 (common/utils.js, common/base-state.js) - TBM 모바일 인라인 JS/CSS 외부 파일로 분리 (tbm-mobile.js, tbm-mobile.css) - 미사용 코드 삭제 (index.js, work-report-*.js 등 5개 파일) - TBM/작업보고 state.js, utils.js를 공통 모듈 기반으로 전환 - 작업보고서 SSO 인증 호환 수정 (token/user 함수) - tbmModel.js: incomplete-reports 쿼리에서 users→sso_users 조인 수정, leader_name 조인 추가 - docker-compose.yml: system1-web 볼륨 마운트 추가 - 모바일 인계(handover) 기능 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
83
user-management/api/projectController.js
Normal file
83
user-management/api/projectController.js
Normal file
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { getAll, getActive, getById, create, update, remove };
|
||||
79
user-management/api/projectModel.js
Normal file
79
user-management/api/projectModel.js
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Project Model
|
||||
*
|
||||
* projects 테이블 CRUD (MariaDB)
|
||||
* System 1과 같은 DB를 공유
|
||||
*/
|
||||
|
||||
const { getPool } = require('./userModel');
|
||||
|
||||
async function getAll() {
|
||||
const db = getPool();
|
||||
const [rows] = await db.query(
|
||||
'SELECT * FROM projects ORDER BY project_id DESC'
|
||||
);
|
||||
return rows;
|
||||
}
|
||||
|
||||
async function getActive() {
|
||||
const db = getPool();
|
||||
const [rows] = await db.query(
|
||||
'SELECT * FROM projects WHERE is_active = TRUE ORDER BY project_name ASC'
|
||||
);
|
||||
return rows;
|
||||
}
|
||||
|
||||
async function getById(id) {
|
||||
const db = getPool();
|
||||
const [rows] = await db.query(
|
||||
'SELECT * FROM projects WHERE project_id = ?',
|
||||
[id]
|
||||
);
|
||||
return rows[0] || null;
|
||||
}
|
||||
|
||||
async function create({ job_no, project_name, contract_date, due_date, delivery_method, site, pm }) {
|
||||
const db = getPool();
|
||||
const [result] = await db.query(
|
||||
`INSERT INTO projects (job_no, project_name, contract_date, due_date, delivery_method, site, pm)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
||||
[job_no, project_name, contract_date || null, due_date || null, delivery_method || null, site || null, pm || null]
|
||||
);
|
||||
return getById(result.insertId);
|
||||
}
|
||||
|
||||
async function update(id, data) {
|
||||
const db = getPool();
|
||||
const fields = [];
|
||||
const values = [];
|
||||
|
||||
if (data.job_no !== undefined) { fields.push('job_no = ?'); values.push(data.job_no); }
|
||||
if (data.project_name !== undefined) { fields.push('project_name = ?'); values.push(data.project_name); }
|
||||
if (data.contract_date !== undefined) { fields.push('contract_date = ?'); values.push(data.contract_date || null); }
|
||||
if (data.due_date !== undefined) { fields.push('due_date = ?'); values.push(data.due_date || null); }
|
||||
if (data.delivery_method !== undefined) { fields.push('delivery_method = ?'); values.push(data.delivery_method); }
|
||||
if (data.site !== undefined) { fields.push('site = ?'); values.push(data.site); }
|
||||
if (data.pm !== undefined) { fields.push('pm = ?'); values.push(data.pm); }
|
||||
if (data.is_active !== undefined) { fields.push('is_active = ?'); values.push(data.is_active); }
|
||||
if (data.project_status !== undefined) { fields.push('project_status = ?'); values.push(data.project_status); }
|
||||
if (data.completed_date !== undefined) { fields.push('completed_date = ?'); values.push(data.completed_date || null); }
|
||||
|
||||
if (fields.length === 0) return getById(id);
|
||||
|
||||
values.push(id);
|
||||
await db.query(
|
||||
`UPDATE projects SET ${fields.join(', ')} WHERE project_id = ?`,
|
||||
values
|
||||
);
|
||||
return getById(id);
|
||||
}
|
||||
|
||||
async function deactivate(id) {
|
||||
const db = getPool();
|
||||
await db.query(
|
||||
'UPDATE projects SET is_active = FALSE, project_status = ? WHERE project_id = ?',
|
||||
['completed', id]
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = { getAll, getActive, getById, create, update, deactivate };
|
||||
17
user-management/api/projectRoutes.js
Normal file
17
user-management/api/projectRoutes.js
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Project Routes
|
||||
*/
|
||||
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const projectController = require('../controllers/projectController');
|
||||
const { requireAuth, requireAdmin } = require('../middleware/auth');
|
||||
|
||||
router.get('/', requireAuth, projectController.getAll);
|
||||
router.get('/active', requireAuth, projectController.getActive);
|
||||
router.get('/:id', requireAuth, projectController.getById);
|
||||
router.post('/', requireAdmin, projectController.create);
|
||||
router.put('/:id', requireAdmin, projectController.update);
|
||||
router.delete('/:id', requireAdmin, projectController.remove);
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user