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>
82 lines
3.1 KiB
JavaScript
82 lines
3.1 KiB
JavaScript
const { getPool } = require('./partnerModel');
|
|
|
|
async function findBySchedule(scheduleId) {
|
|
const db = getPool();
|
|
const [rows] = await db.query(
|
|
`SELECT pc.*, pco.company_name, su.name AS checked_by_name
|
|
FROM partner_work_checkins pc
|
|
LEFT JOIN partner_companies pco ON pc.company_id = pco.id
|
|
LEFT JOIN sso_users su ON pc.checked_by = su.user_id
|
|
WHERE pc.schedule_id = ?
|
|
ORDER BY pc.check_in_time DESC`, [scheduleId]);
|
|
return rows;
|
|
}
|
|
|
|
async function findById(id) {
|
|
const db = getPool();
|
|
const [rows] = await db.query(
|
|
`SELECT pc.*, pco.company_name, su.name AS checked_by_name
|
|
FROM partner_work_checkins pc
|
|
LEFT JOIN partner_companies pco ON pc.company_id = pco.id
|
|
LEFT JOIN sso_users su ON pc.checked_by = su.user_id
|
|
WHERE pc.id = ?`, [id]);
|
|
return rows[0] || null;
|
|
}
|
|
|
|
async function findTodayByCompany(companyId) {
|
|
const db = getPool();
|
|
const [rows] = await db.query(
|
|
`SELECT pc.*, ps.work_description, ps.workplace_name,
|
|
(SELECT COUNT(*) FROM partner_work_reports WHERE checkin_id = pc.id) AS work_report_count
|
|
FROM partner_work_checkins pc
|
|
LEFT JOIN partner_schedules ps ON pc.schedule_id = ps.id
|
|
WHERE pc.company_id = ? AND DATE(pc.check_in_time) = CURDATE()
|
|
ORDER BY pc.check_in_time DESC`, [companyId]);
|
|
return rows;
|
|
}
|
|
|
|
async function checkIn(data) {
|
|
const db = getPool();
|
|
const [result] = await db.query(
|
|
`INSERT INTO partner_work_checkins (schedule_id, company_id, checked_by, check_in_time, worker_names, actual_worker_count, notes)
|
|
VALUES (?, ?, ?, NOW(), ?, ?, ?)`,
|
|
[data.schedule_id, data.company_id, data.checked_by,
|
|
data.worker_names ? JSON.stringify(data.worker_names) : null,
|
|
data.actual_worker_count || null, data.notes || null]);
|
|
return findById(result.insertId);
|
|
}
|
|
|
|
async function checkOut(id) {
|
|
const db = getPool();
|
|
await db.query('UPDATE partner_work_checkins SET check_out_time = NOW() WHERE id = ? AND check_out_time IS NULL', [id]);
|
|
return findById(id);
|
|
}
|
|
|
|
async function update(id, data) {
|
|
const db = getPool();
|
|
const fields = [];
|
|
const values = [];
|
|
if (data.worker_names !== undefined) { fields.push('worker_names = ?'); values.push(data.worker_names ? JSON.stringify(data.worker_names) : null); }
|
|
if (data.actual_worker_count !== undefined) { fields.push('actual_worker_count = ?'); values.push(data.actual_worker_count || null); }
|
|
if (data.notes !== undefined) { fields.push('notes = ?'); values.push(data.notes || null); }
|
|
if (fields.length === 0) return findById(id);
|
|
values.push(id);
|
|
await db.query(`UPDATE partner_work_checkins SET ${fields.join(', ')} WHERE id = ?`, values);
|
|
return findById(id);
|
|
}
|
|
|
|
async function resetCheckout(id) {
|
|
const db = getPool();
|
|
await db.query('UPDATE partner_work_checkins SET check_out_time = NULL WHERE id = ?', [id]);
|
|
}
|
|
|
|
async function countActive() {
|
|
const db = getPool();
|
|
const [rows] = await db.query(
|
|
`SELECT COUNT(*) AS cnt FROM partner_work_checkins
|
|
WHERE check_out_time IS NULL AND DATE(check_in_time) = CURDATE()`);
|
|
return rows[0].cnt;
|
|
}
|
|
|
|
module.exports = { findBySchedule, findById, findTodayByCompany, checkIn, checkOut, update, resetCheckout, countActive };
|