feat(tksupport): Sprint 001 Section C — 전사 휴가관리 구현

- 전사 휴가 부여/관리 (company-holidays) CRUD + 연차차감 트랜잭션
- 전체 휴가관리 대시보드 (vacation-dashboard) 부서별/직원별 현황
- 내 휴가 현황 개선 (/my-status) balance_type별 카드, 전사 휴가일
- requireSupportTeam 미들웨어, 부서명 JOIN, 마이그레이션 002 추가
- 사이드바 roles 기반 메뉴 필터링 (하위호환 유지)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-03-23 08:16:50 +09:00
parent a3f7a324b1
commit 36391c02e1
19 changed files with 1040 additions and 62 deletions

View File

@@ -0,0 +1,76 @@
const companyHolidayModel = require('../models/companyHolidayModel');
const companyHolidayController = {
async getHolidays(req, res) {
try {
const year = parseInt(req.query.year) || new Date().getFullYear();
const holidays = await companyHolidayModel.getByYear(year);
res.json({ success: true, data: holidays });
} catch (error) {
console.error('전사 휴가 조회 오류:', error);
res.status(500).json({ success: false, error: '서버 오류가 발생했습니다' });
}
},
async createHoliday(req, res) {
try {
const { holiday_date, holiday_name, holiday_type, description } = req.body;
if (!holiday_date || !holiday_name || !holiday_type) {
return res.status(400).json({ success: false, error: '필수 필드가 누락되었습니다' });
}
if (!['PAID', 'ANNUAL_DEDUCT'].includes(holiday_type)) {
return res.status(400).json({ success: false, error: '유효하지 않은 휴가 유형입니다' });
}
const created_by = req.user.user_id || req.user.id;
const result = await companyHolidayModel.create({ holiday_date, holiday_name, holiday_type, description, created_by });
res.status(201).json({ success: true, message: '전사 휴가가 등록되었습니다', data: { id: result.insertId } });
} catch (error) {
if (error.code === 'ER_DUP_ENTRY') {
return res.status(400).json({ success: false, error: '해당 날짜에 이미 전사 휴가가 등록되어 있습니다' });
}
console.error('전사 휴가 등록 오류:', error);
res.status(500).json({ success: false, error: '서버 오류가 발생했습니다' });
}
},
async deleteHoliday(req, res) {
try {
const { id } = req.params;
const holiday = await companyHolidayModel.getById(id);
if (!holiday) {
return res.status(404).json({ success: false, error: '해당 전사 휴가를 찾을 수 없습니다' });
}
if (holiday.deduction_applied_at) {
return res.status(400).json({ success: false, error: '차감이 실행된 휴가는 삭제할 수 없습니다' });
}
await companyHolidayModel.delete(id);
res.json({ success: true, message: '전사 휴가가 삭제되었습니다' });
} catch (error) {
console.error('전사 휴가 삭제 오류:', error);
res.status(500).json({ success: false, error: '서버 오류가 발생했습니다' });
}
},
async applyDeduction(req, res) {
try {
const { id } = req.params;
const result = await companyHolidayModel.applyAnnualDeduction(id);
const response = {
success: true,
message: `연차 차감이 완료되었습니다 (${result.affected_count}명 적용)`,
data: result
};
if (result.missing_balance_count > 0) {
response.warning = `${result.missing_balance_count}명의 사원은 연차 잔여일 데이터가 없어 차감되지 않았습니다`;
}
res.json(response);
} catch (error) {
console.error('연차 차감 오류:', error);
res.status(400).json({ success: false, error: error.message });
}
}
};
module.exports = companyHolidayController;

View File

@@ -1,5 +1,6 @@
const vacationRequestModel = require('../models/vacationRequestModel');
const vacationBalanceModel = require('../models/vacationBalanceModel');
const companyHolidayModel = require('../models/companyHolidayModel');
const { getPool } = require('../middleware/auth');
const vacationController = {
@@ -228,6 +229,29 @@ const vacationController = {
}
},
// ─── 내 휴가 현황 ───
async getMyStatus(req, res) {
try {
const userId = req.user.user_id || req.user.id;
const year = parseInt(req.query.year) || new Date().getFullYear();
const startOfYear = `${year}-01-01`;
const endOfYear = `${year}-12-31`;
const [balances, requests, holidays] = await Promise.all([
vacationBalanceModel.getByUserAndYear(userId, year),
vacationRequestModel.getAll({ user_id: userId, start_date: startOfYear, end_date: endOfYear }),
companyHolidayModel.getByYear(year)
]);
res.json({
success: true,
data: { balances, requests, company_holidays: holidays, overtime_hours: null }
});
} catch (error) {
console.error('내 휴가 현황 조회 오류:', error);
res.status(500).json({ success: false, error: '서버 오류가 발생했습니다' });
}
},
// ─── 잔여일 ───
async getMyBalance(req, res) {

View File

@@ -0,0 +1,52 @@
const vacationDashboardModel = require('../models/vacationDashboardModel');
const vacationDashboardController = {
async getDashboard(req, res) {
try {
const year = parseInt(req.query.year) || new Date().getFullYear();
const filters = {
department_id: req.query.department_id || null,
search_name: req.query.search_name || null
};
const [summary, rows] = await Promise.all([
vacationDashboardModel.getSummary(year),
vacationDashboardModel.getEmployeeList(year, filters)
]);
// user_id별 그룹핑
const employeeMap = {};
rows.forEach(row => {
if (!employeeMap[row.user_id]) {
employeeMap[row.user_id] = {
user_id: row.user_id,
name: row.name,
username: row.username,
department_name: row.department_name,
hire_date: row.hire_date,
balances: []
};
}
if (row.id) {
employeeMap[row.user_id].balances.push({
balance_type: row.balance_type,
type_name: row.type_name,
type_code: row.type_code,
total_days: row.total_days,
used_days: row.used_days,
remaining_days: row.remaining_days,
expires_at: row.expires_at
});
}
});
const employees = Object.values(employeeMap);
res.json({ success: true, data: { summary, employees } });
} catch (error) {
console.error('휴가 대시보드 조회 오류:', error);
res.status(500).json({ success: false, error: '서버 오류가 발생했습니다' });
}
}
};
module.exports = vacationDashboardController;