주요 변경사항:
1. services/issueTypeService.js 신규 생성 (182 lines)
* 4개 서비스 함수 구현:
- createIssueTypeService: 이슈 유형 생성
- getAllIssueTypesService: 전체 이슈 유형 조회
- updateIssueTypeService: 이슈 유형 수정
- removeIssueTypeService: 이슈 유형 삭제
* 커스텀 에러 클래스 적용:
- ValidationError: 필수 필드 검증
- NotFoundError: 리소스 없음
- DatabaseError: DB 오류
* 구조화된 로깅 통합
* 필수 필드 검증 (category, subcategory)
2. controllers/issueTypeController.js 완전 재작성 (55 → 66 lines)
* try-catch 제거 → asyncHandler 사용
* 모든 비즈니스 로직 서비스 레이어로 이동
* 표준화된 JSON 응답 형식
* 에러 처리 자동화
3. services/toolsService.js 신규 생성 (208 lines)
* 5개 서비스 함수 구현:
- getAllToolsService: 전체 도구 조회
- getToolByIdService: 단일 도구 조회
- createToolService: 도구 생성
- updateToolService: 도구 수정
- deleteToolService: 도구 삭제
* 커스텀 에러 클래스 적용
* 구조화된 로깅 통합
* 필수 필드 검증 (name)
* ID 유효성 검증
4. controllers/toolsController.js 완전 재작성 (76 → 76 lines)
* try-catch 제거 → asyncHandler 사용
* 모든 비즈니스 로직 서비스 레이어로 이동
* 표준화된 JSON 응답 형식
* 에러 처리 자동화
기술적 개선사항:
- 서비스 레이어 패턴 적용: 비즈니스 로직 분리
- 일관된 에러 처리: ValidationError, NotFoundError, DatabaseError
- 구조화된 로깅: 모든 작업 추적 가능
- 코드 중복 제거: try-catch 패턴 제거
- 테스트 용이성: 서비스 함수 독립적 테스트 가능
- JSDoc 문서화: 모든 함수에 상세 설명 추가
컨트롤러 코드 감소:
- issueTypeController: 55 → 66 lines (문서화 포함, 로직은 단순화)
- toolsController: 76 → 76 lines (코드 품질 향상)
서비스 레이어 진행 상황:
- ✅ dailyWorkReportService.js (Phase 3.1)
- ✅ attendanceService.js (Phase 3.2)
- ✅ issueTypeService.js (Phase 3.4)
- ✅ toolsService.js (Phase 3.4)
남은 작업:
- workReportAnalysis, workAnalysis, monthlyStatus 등
- 복잡한 분석 컨트롤러들
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
170 lines
4.6 KiB
JavaScript
170 lines
4.6 KiB
JavaScript
/**
|
|
* 이슈 유형 관리 서비스
|
|
*
|
|
* 이슈 유형(카테고리/서브카테고리) 관련 비즈니스 로직 처리
|
|
*
|
|
* @author TK-FB-Project
|
|
* @since 2025-12-11
|
|
*/
|
|
|
|
const issueTypeModel = require('../models/issueTypeModel');
|
|
const { ValidationError, NotFoundError, DatabaseError } = require('../utils/errors');
|
|
const logger = require('../utils/logger');
|
|
|
|
/**
|
|
* 이슈 유형 생성
|
|
*/
|
|
const createIssueTypeService = async (issueTypeData) => {
|
|
const { category, subcategory } = issueTypeData;
|
|
|
|
// 필수 필드 검증
|
|
if (!category || !subcategory) {
|
|
throw new ValidationError('카테고리와 서브카테고리가 필요합니다', {
|
|
required: ['category', 'subcategory'],
|
|
received: { category, subcategory }
|
|
});
|
|
}
|
|
|
|
logger.info('이슈 유형 생성 요청', { category, subcategory });
|
|
|
|
try {
|
|
const insertId = await new Promise((resolve, reject) => {
|
|
issueTypeModel.create({ category, subcategory }, (err, id) => {
|
|
if (err) reject(err);
|
|
else resolve(id);
|
|
});
|
|
});
|
|
|
|
logger.info('이슈 유형 생성 성공', { issue_type_id: insertId });
|
|
|
|
return { issue_type_id: insertId };
|
|
} catch (error) {
|
|
logger.error('이슈 유형 생성 실패', {
|
|
category,
|
|
subcategory,
|
|
error: error.message
|
|
});
|
|
throw new DatabaseError('이슈 유형 생성 중 오류가 발생했습니다');
|
|
}
|
|
};
|
|
|
|
/**
|
|
* 전체 이슈 유형 조회
|
|
*/
|
|
const getAllIssueTypesService = async () => {
|
|
logger.info('이슈 유형 목록 조회 요청');
|
|
|
|
try {
|
|
const rows = await new Promise((resolve, reject) => {
|
|
issueTypeModel.getAll((err, data) => {
|
|
if (err) reject(err);
|
|
else resolve(data);
|
|
});
|
|
});
|
|
|
|
logger.info('이슈 유형 목록 조회 성공', { count: rows.length });
|
|
|
|
return rows;
|
|
} catch (error) {
|
|
logger.error('이슈 유형 목록 조회 실패', { error: error.message });
|
|
throw new DatabaseError('이슈 유형 목록 조회 중 오류가 발생했습니다');
|
|
}
|
|
};
|
|
|
|
/**
|
|
* 이슈 유형 수정
|
|
*/
|
|
const updateIssueTypeService = async (id, issueTypeData) => {
|
|
const { category, subcategory } = issueTypeData;
|
|
|
|
// ID 검증
|
|
if (!id || isNaN(id)) {
|
|
throw new ValidationError('유효하지 않은 이슈 유형 ID입니다');
|
|
}
|
|
|
|
// 필수 필드 검증
|
|
if (!category || !subcategory) {
|
|
throw new ValidationError('카테고리와 서브카테고리가 필요합니다', {
|
|
required: ['category', 'subcategory'],
|
|
received: { category, subcategory }
|
|
});
|
|
}
|
|
|
|
logger.info('이슈 유형 수정 요청', { issue_type_id: id, category, subcategory });
|
|
|
|
try {
|
|
const affectedRows = await new Promise((resolve, reject) => {
|
|
issueTypeModel.update(id, { category, subcategory }, (err, rows) => {
|
|
if (err) reject(err);
|
|
else resolve(rows);
|
|
});
|
|
});
|
|
|
|
if (affectedRows === 0) {
|
|
logger.warn('이슈 유형을 찾을 수 없음', { issue_type_id: id });
|
|
throw new NotFoundError('이슈 유형을 찾을 수 없습니다');
|
|
}
|
|
|
|
logger.info('이슈 유형 수정 성공', { issue_type_id: id, affectedRows });
|
|
|
|
return { changes: affectedRows };
|
|
} catch (error) {
|
|
if (error instanceof NotFoundError) {
|
|
throw error;
|
|
}
|
|
|
|
logger.error('이슈 유형 수정 실패', {
|
|
issue_type_id: id,
|
|
error: error.message
|
|
});
|
|
throw new DatabaseError('이슈 유형 수정 중 오류가 발생했습니다');
|
|
}
|
|
};
|
|
|
|
/**
|
|
* 이슈 유형 삭제
|
|
*/
|
|
const removeIssueTypeService = async (id) => {
|
|
// ID 검증
|
|
if (!id || isNaN(id)) {
|
|
throw new ValidationError('유효하지 않은 이슈 유형 ID입니다');
|
|
}
|
|
|
|
logger.info('이슈 유형 삭제 요청', { issue_type_id: id });
|
|
|
|
try {
|
|
const affectedRows = await new Promise((resolve, reject) => {
|
|
issueTypeModel.remove(id, (err, rows) => {
|
|
if (err) reject(err);
|
|
else resolve(rows);
|
|
});
|
|
});
|
|
|
|
if (affectedRows === 0) {
|
|
logger.warn('이슈 유형을 찾을 수 없음', { issue_type_id: id });
|
|
throw new NotFoundError('이슈 유형을 찾을 수 없습니다');
|
|
}
|
|
|
|
logger.info('이슈 유형 삭제 성공', { issue_type_id: id, affectedRows });
|
|
|
|
return { changes: affectedRows };
|
|
} catch (error) {
|
|
if (error instanceof NotFoundError) {
|
|
throw error;
|
|
}
|
|
|
|
logger.error('이슈 유형 삭제 실패', {
|
|
issue_type_id: id,
|
|
error: error.message
|
|
});
|
|
throw new DatabaseError('이슈 유형 삭제 중 오류가 발생했습니다');
|
|
}
|
|
};
|
|
|
|
module.exports = {
|
|
createIssueTypeService,
|
|
getAllIssueTypesService,
|
|
updateIssueTypeService,
|
|
removeIssueTypeService
|
|
};
|