- checkinModel: partner_checkins → partner_work_checkins, countActive() 추가 - workReportModel: partner_work_reports → daily_work_reports - partner-portal: check_out_at/check_in_at → check_out_time/check_in_time - checkinModel findTodayByCompany: LEFT JOIN has_work_report - tkpurchase-core/tksafety-core: navbar match '' 제거 - checkinController: checkOut에 업무현황 검증, stats() 추가 - workReportController: checkin_id 필수 + schedule 일치 검증 - checkinRoutes: GET / 대시보드 통계 라우트 추가 - nginx.conf: visit.html → tksafety 리다이렉트 - migration-purchase-safety.sql: DDL 동기화 - migration-purchase-safety-patch.sql: 신규 패치 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
97 lines
3.3 KiB
JavaScript
97 lines
3.3 KiB
JavaScript
const checkinModel = require('../models/checkinModel');
|
|
const workReportModel = require('../models/workReportModel');
|
|
|
|
// 일정별 체크인 목록
|
|
async function list(req, res) {
|
|
try {
|
|
const rows = await checkinModel.findBySchedule(req.params.scheduleId);
|
|
res.json({ success: true, data: rows });
|
|
} catch (err) {
|
|
console.error('Checkin list error:', err);
|
|
res.status(500).json({ success: false, error: err.message });
|
|
}
|
|
}
|
|
|
|
// 내 체크인 (협력업체 포탈 - 오늘)
|
|
async function myCheckins(req, res) {
|
|
try {
|
|
const companyId = req.user.partner_company_id;
|
|
if (!companyId) {
|
|
return res.status(403).json({ success: false, error: '협력업체 계정이 아닙니다' });
|
|
}
|
|
const rows = await checkinModel.findTodayByCompany(companyId);
|
|
res.json({ success: true, data: rows });
|
|
} catch (err) {
|
|
console.error('Checkin myCheckins error:', err);
|
|
res.status(500).json({ success: false, error: err.message });
|
|
}
|
|
}
|
|
|
|
// 체크인
|
|
async function checkIn(req, res) {
|
|
try {
|
|
const { schedule_id, company_id, worker_names, actual_worker_count } = req.body;
|
|
if (!schedule_id) {
|
|
return res.status(400).json({ success: false, error: '일정을 선택해주세요' });
|
|
}
|
|
const resolvedCompanyId = company_id || req.user.partner_company_id;
|
|
if (!resolvedCompanyId) {
|
|
return res.status(400).json({ success: false, error: '업체 정보가 필요합니다' });
|
|
}
|
|
const data = {
|
|
schedule_id,
|
|
company_id: resolvedCompanyId,
|
|
checked_by: req.user.user_id || req.user.id,
|
|
worker_names,
|
|
actual_worker_count,
|
|
notes: req.body.notes
|
|
};
|
|
const row = await checkinModel.checkIn(data);
|
|
res.status(201).json({ success: true, data: row });
|
|
} catch (err) {
|
|
console.error('Checkin checkIn error:', err);
|
|
res.status(500).json({ success: false, error: err.message });
|
|
}
|
|
}
|
|
|
|
// 체크아웃
|
|
async function checkOut(req, res) {
|
|
try {
|
|
const report = await workReportModel.findByCheckin(req.params.id);
|
|
if (!report) {
|
|
return res.status(400).json({ success: false, error: '업무현황을 먼저 입력해주세요' });
|
|
}
|
|
const row = await checkinModel.checkOut(req.params.id);
|
|
if (!row) return res.status(404).json({ success: false, error: '체크인 기록을 찾을 수 없습니다' });
|
|
res.json({ success: true, data: row });
|
|
} catch (err) {
|
|
console.error('Checkin checkOut error:', err);
|
|
res.status(500).json({ success: false, error: err.message });
|
|
}
|
|
}
|
|
|
|
// 체크인 정보 수정
|
|
async function update(req, res) {
|
|
try {
|
|
const row = await checkinModel.update(req.params.id, req.body);
|
|
if (!row) return res.status(404).json({ success: false, error: '체크인 기록을 찾을 수 없습니다' });
|
|
res.json({ success: true, data: row });
|
|
} catch (err) {
|
|
console.error('Checkin update error:', err);
|
|
res.status(500).json({ success: false, error: err.message });
|
|
}
|
|
}
|
|
|
|
// 대시보드 통계
|
|
async function stats(req, res) {
|
|
try {
|
|
const activeCount = await checkinModel.countActive();
|
|
res.json({ success: true, total: activeCount });
|
|
} catch (err) {
|
|
console.error('Checkin stats error:', err);
|
|
res.status(500).json({ success: false, error: err.message });
|
|
}
|
|
}
|
|
|
|
module.exports = { list, myCheckins, checkIn, checkOut, update, stats };
|