Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | /** * 일일 이슈 보고서 관리 서비스 * * 일일 이슈 보고서 생성, 조회, 삭제 관련 비즈니스 로직 처리 * * @author TK-FB-Project * @since 2025-12-11 */ const dailyIssueReportModel = require('../models/dailyIssueReportModel'); const { ValidationError, NotFoundError, DatabaseError } = require('../utils/errors'); const logger = require('../utils/logger'); /** * 일일 이슈 보고서 생성 * * 한 번에 여러 작업자에 대해 동일한 이슈를 등록할 수 있습니다. * * @param {object} issueData - 컨트롤러에서 전달된 이슈 데이터 * @param {string} issueData.date - 이슈 발생 날짜 (YYYY-MM-DD) * @param {number} issueData.project_id - 프로젝트 ID * @param {string} issueData.start_time - 이슈 시작 시간 * @param {string} issueData.end_time - 이슈 종료 시간 * @param {number} issueData.issue_type_id - 이슈 유형 ID * @param {number[]} issueData.worker_ids - 작업자 ID 배열 * @returns {Promise<object>} 생성 결과 */ const createDailyIssueReportService = async (issueData) => { const { date, project_id, start_time, end_time, issue_type_id, worker_ids } = issueData; // 필수 필드 검증 if (!date || !project_id || !start_time || !end_time || !issue_type_id || !worker_ids) { throw new ValidationError('필수 필드가 누락되었습니다', { required: ['date', 'project_id', 'start_time', 'end_time', 'issue_type_id', 'worker_ids'], received: { date, project_id, start_time, end_time, issue_type_id, worker_ids: !!worker_ids } }); } if (!Array.isArray(worker_ids) || worker_ids.length === 0) { throw new ValidationError('worker_ids는 최소 한 명 이상의 작업자를 포함하는 배열이어야 합니다', { received: { worker_ids, isArray: Array.isArray(worker_ids), length: worker_ids?.length } }); } logger.info('이슈 보고서 생성 요청', { date, project_id, issue_type_id, worker_count: worker_ids.length }); // 모델에 전달할 데이터 준비 const reportsToCreate = worker_ids.map(worker_id => ({ date, project_id, start_time, end_time, issue_type_id, worker_id })); try { const insertedIds = await dailyIssueReportModel.createMany(reportsToCreate); logger.info('이슈 보고서 생성 성공', { count: insertedIds.length, issue_report_ids: insertedIds }); return { message: `${insertedIds.length}개의 이슈 보고서가 성공적으로 생성되었습니다`, issue_report_ids: insertedIds }; } catch (error) { logger.error('이슈 보고서 생성 실패', { date, project_id, worker_ids, error: error.message }); throw new DatabaseError('이슈 보고서 생성 중 오류가 발생했습니다'); } }; /** * 특정 날짜의 모든 이슈 보고서 조회 * * @param {string} date - 조회할 날짜 (YYYY-MM-DD) * @returns {Promise<Array>} 조회된 이슈 보고서 배열 */ const getDailyIssuesByDateService = async (date) => { if (!date) { throw new ValidationError('날짜가 필요합니다', { required: ['date'], received: { date } }); } logger.info('이슈 보고서 날짜별 조회 요청', { date }); try { const issues = await dailyIssueReportModel.getAllByDate(date); logger.info('이슈 보고서 조회 성공', { date, count: issues.length }); return issues; } catch (error) { logger.error('이슈 보고서 조회 실패', { date, error: error.message }); throw new DatabaseError('이슈 보고서 조회 중 오류가 발생했습니다'); } }; /** * 특정 ID의 이슈 보고서 삭제 * * @param {string|number} issueId - 삭제할 이슈 보고서의 ID * @returns {Promise<object>} 삭제 결과 */ const removeDailyIssueService = async (issueId) => { if (!issueId) { throw new ValidationError('이슈 보고서 ID가 필요합니다', { required: ['issue_id'], received: { issueId } }); } logger.info('이슈 보고서 삭제 요청', { issue_id: issueId }); try { const affectedRows = await dailyIssueReportModel.remove(issueId); if (affectedRows === 0) { logger.warn('삭제할 이슈 보고서를 찾을 수 없음', { issue_id: issueId }); throw new NotFoundError('삭제할 이슈 보고서를 찾을 수 없습니다'); } logger.info('이슈 보고서 삭제 성공', { issue_id: issueId, affected_rows: affectedRows }); return { message: '이슈 보고서가 성공적으로 삭제되었습니다', deleted_id: issueId, affected_rows: affectedRows }; } catch (error) { if (error instanceof NotFoundError) { throw error; } logger.error('이슈 보고서 삭제 실패', { issue_id: issueId, error: error.message }); throw new DatabaseError('이슈 보고서 삭제 중 오류가 발생했습니다'); } }; module.exports = { createDailyIssueReportService, getDailyIssuesByDateService, removeDailyIssueService }; |