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:
76
tksupport/api/controllers/companyHolidayController.js
Normal file
76
tksupport/api/controllers/companyHolidayController.js
Normal 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;
|
||||
Reference in New Issue
Block a user