- tkuser 서비스 신규 추가 (API + Web) - 사용자/권한/프로젝트/부서/작업자/작업장/설비/작업/휴가 통합 관리 - 작업장 탭: 공장→작업장 드릴다운 네비게이션 + 구역지도 클릭 연동 - 작업 탭: 공정(work_types)→작업(tasks) 계층 관리 - 휴가 탭: 유형 관리 + 연차 배정(근로기준법 자동계산) - 전 시스템 SSO 쿠키 인증으로 통합 (.technicalkorea.net 공유) - System 2: 작업 이슈 리포트 기능 강화 - System 3: tkuser API 연동, 페이지 권한 체계 적용 - docker-compose에 tkuser-api, tkuser-web 서비스 추가 - ARCHITECTURE.md, DEPLOYMENT.md 문서 작성 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
127 lines
4.8 KiB
JavaScript
127 lines
4.8 KiB
JavaScript
/**
|
|
* Vacation Controller
|
|
*
|
|
* 휴가 유형 + 연차 배정 관리
|
|
*/
|
|
|
|
const vacationModel = require('../models/vacationModel');
|
|
|
|
/* ===== Vacation Types ===== */
|
|
|
|
async function getVacationTypes(req, res, next) {
|
|
try {
|
|
const all = req.query.all === 'true';
|
|
const data = all ? await vacationModel.getAllVacationTypes() : await vacationModel.getVacationTypes();
|
|
res.json({ success: true, data });
|
|
} catch (err) { next(err); }
|
|
}
|
|
|
|
async function createVacationType(req, res, next) {
|
|
try {
|
|
const { type_code, type_name } = req.body;
|
|
if (!type_code || !type_name) return res.status(400).json({ success: false, error: '유형 코드와 이름은 필수입니다' });
|
|
const data = await vacationModel.createVacationType(req.body);
|
|
res.status(201).json({ success: true, data });
|
|
} catch (err) {
|
|
if (err.code === 'ER_DUP_ENTRY') return res.status(409).json({ success: false, error: '이미 존재하는 유형 코드입니다' });
|
|
next(err);
|
|
}
|
|
}
|
|
|
|
async function updateVacationType(req, res, next) {
|
|
try {
|
|
const data = await vacationModel.updateVacationType(parseInt(req.params.id), req.body);
|
|
if (!data) return res.status(404).json({ success: false, error: '휴가 유형을 찾을 수 없습니다' });
|
|
res.json({ success: true, data });
|
|
} catch (err) {
|
|
if (err.code === 'ER_DUP_ENTRY') return res.status(409).json({ success: false, error: '이미 존재하는 유형 코드입니다' });
|
|
next(err);
|
|
}
|
|
}
|
|
|
|
async function deleteVacationType(req, res, next) {
|
|
try {
|
|
await vacationModel.deleteVacationType(parseInt(req.params.id));
|
|
res.json({ success: true, message: '휴가 유형이 비활성화되었습니다' });
|
|
} catch (err) { next(err); }
|
|
}
|
|
|
|
async function updatePriorities(req, res, next) {
|
|
try {
|
|
const { items } = req.body;
|
|
if (!items || !Array.isArray(items)) return res.status(400).json({ success: false, error: 'items 배열이 필요합니다' });
|
|
await vacationModel.updatePriorities(items);
|
|
res.json({ success: true, message: '우선순위가 업데이트되었습니다' });
|
|
} catch (err) { next(err); }
|
|
}
|
|
|
|
/* ===== Vacation Balances ===== */
|
|
|
|
async function getBalancesByYear(req, res, next) {
|
|
try {
|
|
const year = parseInt(req.params.year);
|
|
const data = await vacationModel.getBalancesByYear(year);
|
|
res.json({ success: true, data });
|
|
} catch (err) { next(err); }
|
|
}
|
|
|
|
async function getBalancesByWorkerYear(req, res, next) {
|
|
try {
|
|
const workerId = parseInt(req.params.workerId);
|
|
const year = parseInt(req.params.year);
|
|
const data = await vacationModel.getBalancesByWorkerYear(workerId, year);
|
|
res.json({ success: true, data });
|
|
} catch (err) { next(err); }
|
|
}
|
|
|
|
async function createBalance(req, res, next) {
|
|
try {
|
|
const { worker_id, vacation_type_id, year } = req.body;
|
|
if (!worker_id || !vacation_type_id || !year) {
|
|
return res.status(400).json({ success: false, error: '작업자, 휴가유형, 연도는 필수입니다' });
|
|
}
|
|
const data = await vacationModel.createBalance({ ...req.body, created_by: req.user.user_id });
|
|
res.status(201).json({ success: true, data });
|
|
} catch (err) { next(err); }
|
|
}
|
|
|
|
async function updateBalance(req, res, next) {
|
|
try {
|
|
const data = await vacationModel.updateBalance(parseInt(req.params.id), req.body);
|
|
if (!data) return res.status(404).json({ success: false, error: '배정 정보를 찾을 수 없습니다' });
|
|
res.json({ success: true, data });
|
|
} catch (err) { next(err); }
|
|
}
|
|
|
|
async function deleteBalance(req, res, next) {
|
|
try {
|
|
await vacationModel.deleteBalance(parseInt(req.params.id));
|
|
res.json({ success: true, message: '삭제되었습니다' });
|
|
} catch (err) { next(err); }
|
|
}
|
|
|
|
async function bulkUpsertBalances(req, res, next) {
|
|
try {
|
|
const { balances } = req.body;
|
|
if (!balances || !Array.isArray(balances)) return res.status(400).json({ success: false, error: 'balances 배열이 필요합니다' });
|
|
const items = balances.map(b => ({ ...b, created_by: req.user.user_id }));
|
|
const count = await vacationModel.bulkUpsertBalances(items);
|
|
res.json({ success: true, data: { count }, message: `${count}건 처리되었습니다` });
|
|
} catch (err) { next(err); }
|
|
}
|
|
|
|
async function autoCalculate(req, res, next) {
|
|
try {
|
|
const { year } = req.body;
|
|
if (!year) return res.status(400).json({ success: false, error: '연도는 필수입니다' });
|
|
const result = await vacationModel.autoCalculateForAllWorkers(year, req.user.user_id);
|
|
res.json({ success: true, data: result, message: `${result.count}명 자동 배정 완료` });
|
|
} catch (err) { next(err); }
|
|
}
|
|
|
|
module.exports = {
|
|
getVacationTypes, createVacationType, updateVacationType, deleteVacationType, updatePriorities,
|
|
getBalancesByYear, getBalancesByWorkerYear, createBalance, updateBalance, deleteBalance,
|
|
bulkUpsertBalances, autoCalculate
|
|
};
|