주요 변경사항: - services/attendanceService.js 신규 생성 (269 lines) * 9개 서비스 함수로 비즈니스 로직 분리 * 커스텀 에러 클래스 적용 (ValidationError, DatabaseError) * 구조화된 로깅 시스템 통합 - controllers/attendanceController.js 완전 재작성 (306 → 168 lines, 45% 감소) * 클래스 기반에서 함수 기반 export로 변경 * 모든 비즈니스 로직을 서비스 레이어로 이동 * asyncHandler 미들웨어로 에러 처리 자동화 - controllers/workerController.js 개선 * 커스텀 에러 클래스 적용 * console.log → logger 교체 * 캐시 무효화 로직 유지 - controllers/projectController.js 완전 재작성 (117 → 163 lines) * 모든 함수에 새로운 에러 클래스 적용 * 구조화된 로깅 추가 * 표준화된 JSON 응답 형식 기술 스택: - Custom Error Classes: ValidationError, NotFoundError, DatabaseError - Structured Logging: logger.info/error/warn/debug with context - asyncHandler: Automatic async error handling - Service Layer Pattern: Business logic separation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
168 lines
3.9 KiB
JavaScript
168 lines
3.9 KiB
JavaScript
/**
|
|
* 근태 관리 컨트롤러
|
|
*
|
|
* 근태 기록 API 엔드포인트 핸들러
|
|
*
|
|
* @author TK-FB-Project
|
|
* @since 2025-12-11
|
|
*/
|
|
|
|
const attendanceService = require('../services/attendanceService');
|
|
const { asyncHandler } = require('../middlewares/errorHandler');
|
|
|
|
/**
|
|
* 일일 근태 현황 조회 (대시보드용)
|
|
*/
|
|
const getDailyAttendanceStatus = asyncHandler(async (req, res) => {
|
|
const { date } = req.query;
|
|
const data = await attendanceService.getDailyAttendanceStatusService(date);
|
|
|
|
res.json({
|
|
success: true,
|
|
data,
|
|
message: '근태 현황을 성공적으로 조회했습니다'
|
|
});
|
|
});
|
|
|
|
/**
|
|
* 일일 근태 기록 조회
|
|
*/
|
|
const getDailyAttendanceRecords = asyncHandler(async (req, res) => {
|
|
const { date, worker_id } = req.query;
|
|
const data = await attendanceService.getDailyAttendanceRecordsService(date, worker_id);
|
|
|
|
res.json({
|
|
success: true,
|
|
data,
|
|
message: '근태 기록을 성공적으로 조회했습니다'
|
|
});
|
|
});
|
|
|
|
/**
|
|
* 근태 기록 생성/업데이트
|
|
*/
|
|
const upsertAttendanceRecord = asyncHandler(async (req, res) => {
|
|
const recordData = {
|
|
...req.body,
|
|
created_by: req.user?.user_id || req.user?.id
|
|
};
|
|
|
|
const result = await attendanceService.upsertAttendanceRecordService(recordData);
|
|
|
|
res.json({
|
|
success: true,
|
|
data: result,
|
|
message: '근태 기록이 성공적으로 저장되었습니다'
|
|
});
|
|
});
|
|
|
|
/**
|
|
* 휴가 처리
|
|
*/
|
|
const processVacation = asyncHandler(async (req, res) => {
|
|
const vacationData = {
|
|
record_date: req.body.date,
|
|
worker_id: req.body.worker_id,
|
|
vacation_type_id: req.body.vacation_type,
|
|
created_by: req.user?.user_id || req.user?.id
|
|
};
|
|
|
|
const result = await attendanceService.processVacationService(vacationData);
|
|
|
|
res.json({
|
|
success: true,
|
|
data: result,
|
|
message: '휴가 처리가 성공적으로 완료되었습니다'
|
|
});
|
|
});
|
|
|
|
/**
|
|
* 초과근무 승인
|
|
*/
|
|
const approveOvertime = asyncHandler(async (req, res) => {
|
|
const overtimeData = {
|
|
record_date: req.body.date,
|
|
worker_id: req.body.worker_id,
|
|
overtime_approved: true,
|
|
approved_by: req.user?.user_id || req.user?.id
|
|
};
|
|
|
|
const result = await attendanceService.approveOvertimeService(overtimeData);
|
|
|
|
res.json({
|
|
success: true,
|
|
data: result,
|
|
message: '초과근무가 성공적으로 승인되었습니다'
|
|
});
|
|
});
|
|
|
|
/**
|
|
* 근로 유형 목록 조회
|
|
*/
|
|
const getAttendanceTypes = asyncHandler(async (req, res) => {
|
|
const data = await attendanceService.getAttendanceTypesService();
|
|
|
|
res.json({
|
|
success: true,
|
|
data,
|
|
message: '근로 유형 목록을 성공적으로 조회했습니다'
|
|
});
|
|
});
|
|
|
|
/**
|
|
* 휴가 유형 목록 조회
|
|
*/
|
|
const getVacationTypes = asyncHandler(async (req, res) => {
|
|
const data = await attendanceService.getVacationTypesService();
|
|
|
|
res.json({
|
|
success: true,
|
|
data,
|
|
message: '휴가 유형 목록을 성공적으로 조회했습니다'
|
|
});
|
|
});
|
|
|
|
/**
|
|
* 작업자 휴가 잔여 조회
|
|
*/
|
|
const getWorkerVacationBalance = asyncHandler(async (req, res) => {
|
|
const { worker_id } = req.params;
|
|
const data = await attendanceService.getWorkerVacationBalanceService(parseInt(worker_id));
|
|
|
|
res.json({
|
|
success: true,
|
|
data,
|
|
message: '휴가 잔여 정보를 성공적으로 조회했습니다'
|
|
});
|
|
});
|
|
|
|
/**
|
|
* 월별 근태 통계
|
|
*/
|
|
const getMonthlyAttendanceStats = asyncHandler(async (req, res) => {
|
|
const { year, month, worker_id } = req.query;
|
|
const data = await attendanceService.getMonthlyAttendanceStatsService(
|
|
parseInt(year),
|
|
parseInt(month),
|
|
worker_id ? parseInt(worker_id) : null
|
|
);
|
|
|
|
res.json({
|
|
success: true,
|
|
data,
|
|
message: '월별 근태 통계를 성공적으로 조회했습니다'
|
|
});
|
|
});
|
|
|
|
module.exports = {
|
|
getDailyAttendanceStatus,
|
|
getDailyAttendanceRecords,
|
|
upsertAttendanceRecord,
|
|
processVacation,
|
|
approveOvertime,
|
|
getAttendanceTypes,
|
|
getVacationTypes,
|
|
getWorkerVacationBalance,
|
|
getMonthlyAttendanceStats
|
|
};
|