fix: TBM 작업보고서 저장 버그 수정
문제: 1. dailyWorkReportController에서 DailyWorkReportModel(대문자) 사용 → dailyWorkReportModel(소문자)로 수정 2. daily_work_reports INSERT 쿼리에 work_hours 필드 누락 3. 에러 로그에 스택 트레이스 추가 해결: - 변수명 통일 (dailyWorkReportModel 사용) - INSERT 쿼리에 work_hours 필드 추가 (TBM에서는 total_hours와 동일) - 에러 핸들링 개선 (스택 트레이스 로깅 추가) 영향받는 파일: - api.hyungi.net/controllers/dailyWorkReportController.js (line 878, 887-894) - api.hyungi.net/models/dailyWorkReportModel.js (line 1242-1266) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -827,6 +827,74 @@ const getAccumulatedReports = (req, res) => {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* TBM 배정 기반 작업보고서 생성
|
||||
*/
|
||||
const createFromTbm = async (req, res) => {
|
||||
try {
|
||||
const {
|
||||
tbm_assignment_id,
|
||||
tbm_session_id,
|
||||
worker_id,
|
||||
project_id,
|
||||
work_type_id,
|
||||
report_date,
|
||||
start_time,
|
||||
end_time,
|
||||
total_hours,
|
||||
error_hours,
|
||||
error_type_id,
|
||||
work_status_id
|
||||
} = req.body;
|
||||
|
||||
// 필수 필드 검증
|
||||
if (!tbm_assignment_id || !tbm_session_id || !worker_id || !report_date || !total_hours) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: '필수 필드가 누락되었습니다. (assignment_id, session_id, worker_id, report_date, total_hours)'
|
||||
});
|
||||
}
|
||||
|
||||
// regular_hours 계산
|
||||
const regular_hours = total_hours - (error_hours || 0);
|
||||
|
||||
const reportData = {
|
||||
tbm_assignment_id,
|
||||
tbm_session_id,
|
||||
worker_id,
|
||||
project_id,
|
||||
work_type_id,
|
||||
report_date,
|
||||
start_time,
|
||||
end_time,
|
||||
total_hours,
|
||||
error_hours: error_hours || 0,
|
||||
regular_hours,
|
||||
work_status_id: work_status_id || (error_hours > 0 ? 2 : 1), // error_hours가 있으면 상태 2 (부적합)
|
||||
error_type_id,
|
||||
created_by: req.user.user_id
|
||||
};
|
||||
|
||||
const result = await dailyWorkReportModel.createFromTbmAssignment(reportData);
|
||||
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
message: '작업보고서가 생성되었습니다.',
|
||||
data: result
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
console.error('TBM 작업보고서 생성 오류:', err);
|
||||
console.error('Error stack:', err.stack);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: 'TBM 작업보고서 생성 중 오류가 발생했습니다.',
|
||||
error: err.message,
|
||||
stack: process.env.NODE_ENV === 'development' ? err.stack : undefined
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 모든 컨트롤러 함수 내보내기 (리팩토링된 함수 위주로 재구성)
|
||||
module.exports = {
|
||||
// 📝 V2 핵심 CRUD 함수
|
||||
@@ -834,7 +902,8 @@ module.exports = {
|
||||
getDailyWorkReports,
|
||||
updateWorkReport,
|
||||
removeDailyWorkReport,
|
||||
|
||||
createFromTbm,
|
||||
|
||||
// 📊 V2 통계 및 요약 함수
|
||||
getWorkReportStats,
|
||||
getDailySummary,
|
||||
@@ -851,7 +920,7 @@ module.exports = {
|
||||
getWorkTypes,
|
||||
getWorkStatusTypes,
|
||||
getErrorTypes,
|
||||
|
||||
|
||||
// 🔽 마스터 데이터 CRUD
|
||||
createWorkType,
|
||||
updateWorkType,
|
||||
|
||||
Reference in New Issue
Block a user