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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | /** * 근태 관리 서비스 * * 근태 기록 관련 비즈니스 로직 처리 * * @author TK-FB-Project * @since 2025-12-11 */ const AttendanceModel = require('../models/attendanceModel'); const { ValidationError, NotFoundError, DatabaseError } = require('../utils/errors'); const logger = require('../utils/logger'); /** * 일일 근태 현황 조회 */ const getDailyAttendanceStatusService = async (date) => { if (!date) { throw new ValidationError('날짜가 필요합니다', { required: ['date'], received: { date } }); } logger.info('일일 근태 현황 조회 요청', { date }); try { const attendanceStatus = await AttendanceModel.getWorkerAttendanceStatus(date); logger.info('일일 근태 현황 조회 성공', { date, count: attendanceStatus.length }); return attendanceStatus; } catch (error) { logger.error('일일 근태 현황 조회 실패', { date, error: error.message }); throw new DatabaseError('근태 현황 조회 중 데이터베이스 오류가 발생했습니다'); } }; /** * 일일 근태 기록 조회 */ const getDailyAttendanceRecordsService = async (date, workerId = null) => { if (!date) { throw new ValidationError('날짜가 필요합니다', { required: ['date'], received: { date } }); } logger.info('일일 근태 기록 조회 요청', { date, workerId }); try { const records = await AttendanceModel.getDailyAttendanceRecords(date, workerId); logger.info('일일 근태 기록 조회 성공', { date, count: records.length }); return records; } catch (error) { logger.error('일일 근태 기록 조회 실패', { date, error: error.message }); throw new DatabaseError('근태 기록 조회 중 데이터베이스 오류가 발생했습니다'); } }; /** * 근태 기록 생성/업데이트 */ const upsertAttendanceRecordService = async (recordData) => { const { record_date, worker_id, total_work_hours, attendance_type_id, vacation_type_id, is_vacation_processed, overtime_approved, status, notes } = recordData; // 필수 필드 검증 if (!record_date || !worker_id) { throw new ValidationError('필수 필드가 누락되었습니다', { required: ['record_date', 'worker_id'], received: { record_date, worker_id } }); } logger.info('근태 기록 저장 요청', { record_date, worker_id }); try { const result = await AttendanceModel.upsertAttendanceRecord({ record_date, worker_id, total_work_hours, attendance_type_id, vacation_type_id, is_vacation_processed, overtime_approved, status, notes }); logger.info('근태 기록 저장 성공', { record_date, worker_id }); return result; } catch (error) { logger.error('근태 기록 저장 실패', { record_date, worker_id, error: error.message }); throw new DatabaseError('근태 기록 저장 중 데이터베이스 오류가 발생했습니다'); } }; /** * 휴가 처리 */ const processVacationService = async (vacationData) => { const { record_date, worker_id, vacation_type_id } = vacationData; if (!record_date || !worker_id || !vacation_type_id) { throw new ValidationError('필수 필드가 누락되었습니다', { required: ['record_date', 'worker_id', 'vacation_type_id'], received: { record_date, worker_id, vacation_type_id } }); } logger.info('휴가 처리 요청', { record_date, worker_id, vacation_type_id }); try { const result = await AttendanceModel.processVacation({ record_date, worker_id, vacation_type_id }); logger.info('휴가 처리 성공', { record_date, worker_id }); return result; } catch (error) { logger.error('휴가 처리 실패', { record_date, worker_id, error: error.message }); throw new DatabaseError('휴가 처리 중 데이터베이스 오류가 발생했습니다'); } }; /** * 초과 근무 승인 */ const approveOvertimeService = async (overtimeData) => { const { record_date, worker_id, overtime_approved } = overtimeData; if (!record_date || !worker_id || overtime_approved === undefined) { throw new ValidationError('필수 필드가 누락되었습니다', { required: ['record_date', 'worker_id', 'overtime_approved'], received: { record_date, worker_id, overtime_approved } }); } logger.info('초과 근무 승인 요청', { record_date, worker_id, overtime_approved }); try { const result = await AttendanceModel.approveOvertime({ record_date, worker_id, overtime_approved }); logger.info('초과 근무 승인 처리 성공', { record_date, worker_id }); return result; } catch (error) { logger.error('초과 근무 승인 실패', { record_date, worker_id, error: error.message }); throw new DatabaseError('초과 근무 승인 중 데이터베이스 오류가 발생했습니다'); } }; /** * 근태 유형 목록 조회 */ const getAttendanceTypesService = async () => { logger.info('근태 유형 목록 조회 요청'); try { const types = await AttendanceModel.getAttendanceTypes(); logger.info('근태 유형 목록 조회 성공', { count: types.length }); return types; } catch (error) { logger.error('근태 유형 목록 조회 실패', { error: error.message }); throw new DatabaseError('근태 유형 목록 조회 중 데이터베이스 오류가 발생했습니다'); } }; /** * 휴가 유형 목록 조회 */ const getVacationTypesService = async () => { logger.info('휴가 유형 목록 조회 요청'); try { const types = await AttendanceModel.getVacationTypes(); logger.info('휴가 유형 목록 조회 성공', { count: types.length }); return types; } catch (error) { logger.error('휴가 유형 목록 조회 실패', { error: error.message }); throw new DatabaseError('휴가 유형 목록 조회 중 데이터베이스 오류가 발생했습니다'); } }; /** * 작업자 휴가 잔여 일수 조회 */ const getWorkerVacationBalanceService = async (workerId) => { if (!workerId) { throw new ValidationError('작업자 ID가 필요합니다', { required: ['worker_id'], received: { workerId } }); } logger.info('휴가 잔여 일수 조회 요청', { workerId }); try { const balance = await AttendanceModel.getWorkerVacationBalance(workerId); logger.info('휴가 잔여 일수 조회 성공', { workerId }); return balance; } catch (error) { logger.error('휴가 잔여 일수 조회 실패', { workerId, error: error.message }); throw new DatabaseError('휴가 잔여 일수 조회 중 데이터베이스 오류가 발생했습니다'); } }; /** * 월별 근태 통계 조회 */ const getMonthlyAttendanceStatsService = async (year, month, workerId = null) => { if (!year || !month) { throw new ValidationError('연도와 월이 필요합니다', { required: ['year', 'month'], received: { year, month } }); } logger.info('월별 근태 통계 조회 요청', { year, month, workerId }); try { const stats = await AttendanceModel.getMonthlyAttendanceStats(year, month, workerId); logger.info('월별 근태 통계 조회 성공', { year, month }); return stats; } catch (error) { logger.error('월별 근태 통계 조회 실패', { year, month, error: error.message }); throw new DatabaseError('월별 근태 통계 조회 중 데이터베이스 오류가 발생했습니다'); } }; module.exports = { getDailyAttendanceStatusService, getDailyAttendanceRecordsService, upsertAttendanceRecordService, processVacationService, approveOvertimeService, getAttendanceTypesService, getVacationTypesService, getWorkerVacationBalanceService, getMonthlyAttendanceStatsService }; |