주요 변경사항:
1. services/analysisService.js 개선 (48 → 82 lines, 71% 증가)
* console.error → logger 교체:
- logger.info: 요청/성공 로깅
- logger.error: 실패 로깅
* Error → 커스텀 에러 클래스 적용:
- ValidationError: 필수 필드 검증
- DatabaseError: DB 오류
* 상세한 로깅 추가:
- 총 근무시간, 프로젝트 수, 작업자 수, 상세 건수 추적
* JSDoc 문서화 개선
2. controllers/analysisController.js 개선 (22 → 30 lines)
* try-catch 제거 → asyncHandler 사용
* console.error 제거
* 표준화된 JSON 응답 형식
3. services/workReportService.js 신규 생성 (308 lines)
* 7개 서비스 함수 구현:
- createWorkReportService: 단일/다중 보고서 생성
- getWorkReportsByDateService: 날짜별 조회
- getWorkReportsInRangeService: 기간별 조회
- getWorkReportByIdService: 단일 조회
- updateWorkReportService: 수정
- removeWorkReportService: 삭제
- getSummaryService: 월간 요약
* 커스텀 에러 클래스 적용
* 구조화된 로깅 통합
* 필수 필드 검증
* 배열/단일 데이터 모두 지원
4. controllers/workReportController.js 완전 재작성 (134 → 109 lines, 19% 감소)
* try-catch 제거 → asyncHandler 사용
* 모든 비즈니스 로직 서비스 레이어로 이동
* 표준화된 JSON 응답 형식
* 에러 처리 자동화
* 7개 엔드포인트 모두 개선
기술적 개선사항:
- 일관된 에러 처리: ValidationError, NotFoundError, DatabaseError
- 구조화된 로깅: 모든 작업 추적 가능
- 코드 중복 제거: try-catch 패턴 완전 제거
- 테스트 용이성: 서비스 함수 독립적 테스트 가능
- 유지보수성: 비즈니스 로직과 HTTP 레이어 완전 분리
서비스 레이어 진행 상황:
- ✅ dailyWorkReportService.js (Phase 3.1)
- ✅ attendanceService.js (Phase 3.2)
- ✅ issueTypeService.js (Phase 3.4)
- ✅ toolsService.js (Phase 3.4)
- ✅ dailyIssueReportService.js (Phase 3.5 - 개선)
- ✅ uploadService.js (Phase 3.5)
- ✅ analysisService.js (Phase 3.6 - 개선)
- ✅ workReportService.js (Phase 3.6)
- ✅ auth.service.js (기존)
총 9개 서비스 레이어 구축 완료
컨트롤러 개선 현황:
- ✅ 14/16 개 컨트롤러 개선 완료 (87.5%)
남은 컨트롤러:
- workReportAnalysisController
- workAnalysisController
- monthlyStatusController
- systemController
- authController
- userController (일부)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
109 lines
2.5 KiB
JavaScript
109 lines
2.5 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: '월간 요약 조회 성공'
|
|
});
|
|
});
|