feat: 다수 기능 개선 - 순찰, 출근, 작업분석, 모바일 UI 등
- 순찰/점검 기능 개선 (zone-detail 페이지 추가) - 출근/근태 시스템 개선 (연차 조회, 근무현황) - 작업분석 대분류 그룹화 및 마이그레이션 스크립트 - 모바일 네비게이션 UI 추가 - NAS 배포 도구 및 문서 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,170 @@
|
||||
/**
|
||||
* 일일 이슈 보고서 관리 서비스
|
||||
*
|
||||
* 일일 이슈 보고서 생성, 조회, 삭제 관련 비즈니스 로직 처리
|
||||
*
|
||||
* @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
|
||||
};
|
||||
Reference in New Issue
Block a user