feat(tksafety): 체크리스트 작업별 항목에 tkuser 작업(task) 참조 연동
- getAllChecks: tasks/work_types/weather_conditions JOIN + 프론트엔드 필드명 alias - createCheck/updateCheck: item_type→check_type 등 프론트-DB 필드 매핑 - 모달에 작업(task) 드롭다운 추가, 공정 선택 시 동적 로드 - renderWorktypeItems: work_type → task 2단 그룹핑 - openEditItem: async/await로 task 목록 로드 후 값 설정 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -23,7 +23,7 @@ exports.getCheckById = async (req, res) => {
|
||||
|
||||
exports.createCheck = async (req, res) => {
|
||||
try {
|
||||
if (!req.body.check_item) return res.status(400).json({ success: false, error: 'check_item은 필수입니다' });
|
||||
if (!req.body.item_content && !req.body.check_item) return res.status(400).json({ success: false, error: '점검 항목 내용은 필수입니다' });
|
||||
const checkId = await checklistModel.createCheck(req.body);
|
||||
res.status(201).json({ success: true, message: '항목이 추가되었습니다', data: { check_id: checkId } });
|
||||
} catch (err) {
|
||||
|
||||
@@ -3,7 +3,19 @@ const { getPool } = require('../middleware/auth');
|
||||
// Get all safety checks
|
||||
async function getAllChecks() {
|
||||
const db = getPool();
|
||||
const [rows] = await db.query('SELECT * FROM tbm_safety_checks ORDER BY check_type, check_category, display_order, check_id');
|
||||
const [rows] = await db.query(`
|
||||
SELECT c.check_id AS item_id, c.check_type AS item_type,
|
||||
c.check_item AS item_content, c.check_category AS category,
|
||||
c.display_order, c.is_active, c.is_required, c.description,
|
||||
c.weather_condition, wc.condition_name AS weather_condition_name,
|
||||
wc.condition_code AS weather_condition_id,
|
||||
c.task_id, t.task_name, t.work_type_id, wt.name AS work_type_name
|
||||
FROM tbm_safety_checks c
|
||||
LEFT JOIN tasks t ON c.task_id = t.task_id
|
||||
LEFT JOIN work_types wt ON t.work_type_id = wt.id
|
||||
LEFT JOIN weather_conditions wc ON c.weather_condition = wc.condition_code
|
||||
ORDER BY c.check_type, c.check_category, c.display_order, c.check_id
|
||||
`);
|
||||
return rows;
|
||||
}
|
||||
|
||||
@@ -14,24 +26,32 @@ async function getCheckById(checkId) {
|
||||
return rows[0];
|
||||
}
|
||||
|
||||
// Create check
|
||||
// Create check (frontend field names → DB column mapping)
|
||||
async function createCheck(data) {
|
||||
const db = getPool();
|
||||
const { check_type, check_category, check_item, description, is_required, display_order, weather_condition, task_id } = data;
|
||||
const check_type = data.item_type || data.check_type;
|
||||
const check_category = data.category || data.check_category || null;
|
||||
const check_item = data.item_content || data.check_item;
|
||||
const weather_condition = data.weather_condition_id || data.weather_condition || null;
|
||||
const { description, is_required, display_order, task_id } = data;
|
||||
const [result] = await db.query(
|
||||
'INSERT INTO tbm_safety_checks (check_type, check_category, check_item, description, is_required, display_order, weather_condition, task_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
[check_type, check_category || null, check_item, description || null, is_required ? 1 : 0, display_order || 0, weather_condition || null, task_id || null]
|
||||
[check_type, check_category, check_item, description || null, is_required ? 1 : 0, display_order || 0, weather_condition, task_id || null]
|
||||
);
|
||||
return result.insertId;
|
||||
}
|
||||
|
||||
// Update check
|
||||
// Update check (frontend field names → DB column mapping)
|
||||
async function updateCheck(checkId, data) {
|
||||
const db = getPool();
|
||||
const { check_type, check_category, check_item, description, is_required, display_order, weather_condition, task_id } = data;
|
||||
const check_type = data.item_type || data.check_type;
|
||||
const check_category = data.category || data.check_category || null;
|
||||
const check_item = data.item_content || data.check_item;
|
||||
const weather_condition = data.weather_condition_id || data.weather_condition || null;
|
||||
const { description, is_required, display_order, task_id } = data;
|
||||
const [result] = await db.query(
|
||||
'UPDATE tbm_safety_checks SET check_type = ?, check_category = ?, check_item = ?, description = ?, is_required = ?, display_order = ?, weather_condition = ?, task_id = ? WHERE check_id = ?',
|
||||
[check_type, check_category || null, check_item, description || null, is_required ? 1 : 0, display_order || 0, weather_condition || null, task_id || null, checkId]
|
||||
[check_type, check_category, check_item, description || null, is_required ? 1 : 0, display_order || 0, weather_condition, task_id || null, checkId]
|
||||
);
|
||||
return result;
|
||||
}
|
||||
@@ -53,14 +73,14 @@ async function getWeatherConditions() {
|
||||
// Get work types
|
||||
async function getWorkTypes() {
|
||||
const db = getPool();
|
||||
const [rows] = await db.query('SELECT * FROM work_types ORDER BY name');
|
||||
const [rows] = await db.query('SELECT id AS work_type_id, name AS work_type_name, category, description FROM work_types ORDER BY name');
|
||||
return rows;
|
||||
}
|
||||
|
||||
// Get tasks by work type
|
||||
async function getTasksByWorkType(workTypeId) {
|
||||
const db = getPool();
|
||||
const [rows] = await db.query('SELECT * FROM tasks WHERE work_type_id = ? ORDER BY task_name', [workTypeId]);
|
||||
const [rows] = await db.query('SELECT task_id, task_name, work_type_id, description, is_active FROM tasks WHERE work_type_id = ? AND is_active = TRUE ORDER BY task_name', [workTypeId]);
|
||||
return rows;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user