Files
tk-factory-services/tksafety/api/models/checklistModel.js
Hyungi Ahn 9fda89a374 feat: 안전 코드 tksafety 이관 + 사용자 관리 정리 + UI Tailwind 전환
Phase 1: tksafety에 출입신청/체크리스트 API·웹 추가, tkfb 안전 코드 삭제
Phase 2: 사용자 관리 페이지 삭제, API 축소, 알림 수신자 tkuser 이관
Phase 3: tkuser 권한 페이지 정의 업데이트
Phase 4: 전체 34개 페이지 Tailwind CSS + tkfb-core.js 전환,
         미사용 CSS 20개·인프라 JS 10개·템플릿·컴포넌트 삭제

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 10:46:22 +09:00

68 lines
2.6 KiB
JavaScript

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');
return rows;
}
// Get check by ID
async function getCheckById(checkId) {
const db = getPool();
const [rows] = await db.query('SELECT * FROM tbm_safety_checks WHERE check_id = ?', [checkId]);
return rows[0];
}
// Create check
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 [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]
);
return result.insertId;
}
// Update check
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 [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]
);
return result;
}
// Delete check
async function deleteCheck(checkId) {
const db = getPool();
const [result] = await db.query('DELETE FROM tbm_safety_checks WHERE check_id = ?', [checkId]);
return result;
}
// Get weather conditions
async function getWeatherConditions() {
const db = getPool();
const [rows] = await db.query('SELECT * FROM tbm_weather_conditions ORDER BY display_order, condition_code');
return rows;
}
// Get work types
async function getWorkTypes() {
const db = getPool();
const [rows] = await db.query('SELECT * 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]);
return rows;
}
module.exports = { getAllChecks, getCheckById, createCheck, updateCheck, deleteCheck, getWeatherConditions, getWorkTypes, getTasksByWorkType };