Files
tk-factory-services/system1-factory/api/controllers/workReportController.js
Hyungi Ahn 550633b89d feat: 3-System 분리 프로젝트 초기 코드 작성
TK-FB(공장관리+신고)와 M-Project(부적합관리)를 3개 독립 시스템으로
분리하기 위한 전체 코드 구조 작성.
- SSO 인증 서비스 (bcrypt + pbkdf2 이중 해시 지원)
- System 1: 공장관리 (TK-FB 기반, 신고 코드 제거)
- System 2: 신고 (TK-FB에서 workIssue 코드 추출)
- System 3: 부적합관리 (M-Project 기반)
- Gateway 포털 (path-based 라우팅)
- 통합 docker-compose.yml 및 배포 스크립트

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 14:40:11 +09:00

176 lines
4.1 KiB
JavaScript

/**
* 작업 보고서 관리 컨트롤러
*
* 작업 보고서 CRUD API 엔드포인트 핸들러
*
* @author TK-FB-Project
* @since 2025-12-11
*/
const workReportService = require('../services/workReportService');
const { asyncHandler } = require('../middlewares/errorHandler');
/**
* 작업 보고서 생성 (단일 또는 다중)
*/
exports.createWorkReport = asyncHandler(async (req, res) => {
const result = await workReportService.createWorkReportService(req.body);
res.json({
success: true,
data: result,
message: '작업 보고서가 성공적으로 생성되었습니다'
});
});
/**
* 날짜별 작업 보고서 조회
*/
exports.getWorkReportsByDate = asyncHandler(async (req, res) => {
const { date } = req.params;
const rows = await workReportService.getWorkReportsByDateService(date);
res.json({
success: true,
data: rows,
message: '작업 보고서 조회 성공'
});
});
/**
* 기간별 작업 보고서 조회
*/
exports.getWorkReportsInRange = asyncHandler(async (req, res) => {
const { start, end } = req.query;
const rows = await workReportService.getWorkReportsInRangeService(start, end);
res.json({
success: true,
data: rows,
message: '작업 보고서 조회 성공'
});
});
/**
* 단일 작업 보고서 조회
*/
exports.getWorkReportById = asyncHandler(async (req, res) => {
const { id } = req.params;
const row = await workReportService.getWorkReportByIdService(id);
res.json({
success: true,
data: row,
message: '작업 보고서 조회 성공'
});
});
/**
* 작업 보고서 수정
*/
exports.updateWorkReport = asyncHandler(async (req, res) => {
const { id } = req.params;
const result = await workReportService.updateWorkReportService(id, req.body);
res.json({
success: true,
data: result,
message: '작업 보고서가 성공적으로 수정되었습니다'
});
});
/**
* 작업 보고서 삭제
*/
exports.removeWorkReport = asyncHandler(async (req, res) => {
const { id } = req.params;
const result = await workReportService.removeWorkReportService(id);
res.json({
success: true,
data: result,
message: '작업 보고서가 성공적으로 삭제되었습니다'
});
});
/**
* 월간 요약 조회
*/
exports.getSummary = asyncHandler(async (req, res) => {
const { year, month } = req.query;
const rows = await workReportService.getSummaryService(year, month);
res.json({
success: true,
data: rows,
message: '월간 요약 조회 성공'
});
});
// ========== 부적합 원인 관리 API ==========
/**
* 작업 보고서의 부적합 원인 목록 조회
*/
exports.getReportDefects = asyncHandler(async (req, res) => {
const { reportId } = req.params;
const rows = await workReportService.getReportDefectsService(reportId);
res.json({
success: true,
data: rows,
message: '부적합 원인 조회 성공'
});
});
/**
* 부적합 원인 저장 (전체 교체)
* 기존 부적합 원인을 모두 삭제하고 새로 저장
*/
exports.saveReportDefects = asyncHandler(async (req, res) => {
const { reportId } = req.params;
const { defects } = req.body; // [{ error_type_id, defect_hours, note }]
const result = await workReportService.saveReportDefectsService(reportId, defects);
res.json({
success: true,
data: result,
message: '부적합 원인이 저장되었습니다'
});
});
/**
* 부적합 원인 추가 (단일)
*/
exports.addReportDefect = asyncHandler(async (req, res) => {
const { reportId } = req.params;
const { error_type_id, defect_hours, note } = req.body;
const result = await workReportService.addReportDefectService(reportId, {
error_type_id,
defect_hours,
note
});
res.json({
success: true,
data: result,
message: '부적합 원인이 추가되었습니다'
});
});
/**
* 부적합 원인 삭제
*/
exports.removeReportDefect = asyncHandler(async (req, res) => {
const { defectId } = req.params;
const result = await workReportService.removeReportDefectService(defectId);
res.json({
success: true,
data: result,
message: '부적합 원인이 삭제되었습니다'
});
});