refactor: worker_id → user_id 전체 마이그레이션 (Phase 1-4)
sso_users.user_id를 단일 식별자로 통합. JWT에서 worker_id 제거, department_id/is_production 추가. 백엔드 15개 모델, 11개 컨트롤러, 4개 서비스, 7개 라우트, 프론트엔드 32+ JS/11+ HTML 변환. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -53,7 +53,7 @@ const getDailyAttendanceStatusService = async (date) => {
|
||||
/**
|
||||
* 일일 근태 기록 조회
|
||||
*/
|
||||
const getDailyAttendanceRecordsService = async (date, workerId = null) => {
|
||||
const getDailyAttendanceRecordsService = async (date, userId = null) => {
|
||||
if (!date) {
|
||||
throw new ValidationError('날짜가 필요합니다', {
|
||||
required: ['date'],
|
||||
@@ -61,10 +61,10 @@ const getDailyAttendanceRecordsService = async (date, workerId = null) => {
|
||||
});
|
||||
}
|
||||
|
||||
logger.info('일일 근태 기록 조회 요청', { date, workerId });
|
||||
logger.info('일일 근태 기록 조회 요청', { date, userId });
|
||||
|
||||
try {
|
||||
const records = await AttendanceModel.getDailyAttendanceRecords(date, workerId);
|
||||
const records = await AttendanceModel.getDailyAttendanceRecords(date, userId);
|
||||
logger.info('일일 근태 기록 조회 성공', { date, count: records.length });
|
||||
return records;
|
||||
} catch (error) {
|
||||
@@ -76,7 +76,7 @@ const getDailyAttendanceRecordsService = async (date, workerId = null) => {
|
||||
/**
|
||||
* 기간별 근태 기록 조회 (월별 조회용)
|
||||
*/
|
||||
const getAttendanceRecordsByRangeService = async (startDate, endDate, workerId = null) => {
|
||||
const getAttendanceRecordsByRangeService = async (startDate, endDate, userId = null) => {
|
||||
if (!startDate || !endDate) {
|
||||
throw new ValidationError('시작 날짜와 종료 날짜가 필요합니다', {
|
||||
required: ['start_date', 'end_date'],
|
||||
@@ -84,10 +84,10 @@ const getAttendanceRecordsByRangeService = async (startDate, endDate, workerId =
|
||||
});
|
||||
}
|
||||
|
||||
logger.info('기간별 근태 기록 조회 요청', { startDate, endDate, workerId });
|
||||
logger.info('기간별 근태 기록 조회 요청', { startDate, endDate, userId });
|
||||
|
||||
try {
|
||||
const records = await AttendanceModel.getDailyRecords(startDate, endDate, workerId);
|
||||
const records = await AttendanceModel.getDailyRecords(startDate, endDate, userId);
|
||||
logger.info('기간별 근태 기록 조회 성공', { startDate, endDate, count: records.length });
|
||||
return records;
|
||||
} catch (error) {
|
||||
@@ -103,7 +103,7 @@ const getAttendanceRecordsByRangeService = async (startDate, endDate, workerId =
|
||||
const upsertAttendanceRecordService = async (recordData) => {
|
||||
const {
|
||||
record_date,
|
||||
worker_id,
|
||||
user_id,
|
||||
total_work_hours,
|
||||
attendance_type_id,
|
||||
vacation_type_id,
|
||||
@@ -115,25 +115,25 @@ const upsertAttendanceRecordService = async (recordData) => {
|
||||
} = recordData;
|
||||
|
||||
// 필수 필드 검증
|
||||
if (!record_date || !worker_id) {
|
||||
if (!record_date || !user_id) {
|
||||
throw new ValidationError('필수 필드가 누락되었습니다', {
|
||||
required: ['record_date', 'worker_id'],
|
||||
received: { record_date, worker_id }
|
||||
required: ['record_date', 'user_id'],
|
||||
received: { record_date, user_id }
|
||||
});
|
||||
}
|
||||
|
||||
logger.info('근태 기록 저장 요청', { record_date, worker_id, vacation_type_id });
|
||||
logger.info('근태 기록 저장 요청', { record_date, user_id, vacation_type_id });
|
||||
|
||||
try {
|
||||
// 1. 기존 기록 조회 (휴가 연동을 위해)
|
||||
const existingRecords = await AttendanceModel.getDailyAttendanceRecords(record_date, worker_id);
|
||||
const existingRecord = existingRecords.find(r => r.worker_id === worker_id);
|
||||
const existingRecords = await AttendanceModel.getDailyAttendanceRecords(record_date, user_id);
|
||||
const existingRecord = existingRecords.find(r => r.user_id === user_id);
|
||||
const previousVacationTypeId = existingRecord?.vacation_type_id || null;
|
||||
|
||||
// 2. 근태 기록 저장
|
||||
const result = await AttendanceModel.upsertAttendanceRecord({
|
||||
record_date,
|
||||
worker_id,
|
||||
user_id,
|
||||
total_work_hours,
|
||||
work_attendance_type_id: attendance_type_id,
|
||||
vacation_type_id,
|
||||
@@ -150,21 +150,21 @@ const upsertAttendanceRecordService = async (recordData) => {
|
||||
if (previousDays !== newDays) {
|
||||
// 이전 휴가 복구
|
||||
if (previousDays > 0) {
|
||||
await vacationBalanceModel.restoreByPriority(worker_id, year, previousDays);
|
||||
logger.info('휴가 잔액 복구', { worker_id, year, restored: previousDays });
|
||||
await vacationBalanceModel.restoreByPriority(user_id, year, previousDays);
|
||||
logger.info('휴가 잔액 복구', { user_id, year, restored: previousDays });
|
||||
}
|
||||
|
||||
// 새 휴가 차감
|
||||
if (newDays > 0) {
|
||||
await vacationBalanceModel.deductByPriority(worker_id, year, newDays);
|
||||
logger.info('휴가 잔액 차감', { worker_id, year, deducted: newDays });
|
||||
await vacationBalanceModel.deductByPriority(user_id, year, newDays);
|
||||
logger.info('휴가 잔액 차감', { user_id, year, deducted: newDays });
|
||||
}
|
||||
}
|
||||
|
||||
logger.info('근태 기록 저장 성공', { record_date, worker_id });
|
||||
logger.info('근태 기록 저장 성공', { record_date, user_id });
|
||||
return result;
|
||||
} catch (error) {
|
||||
logger.error('근태 기록 저장 실패', { record_date, worker_id, error: error.message });
|
||||
logger.error('근태 기록 저장 실패', { record_date, user_id, error: error.message });
|
||||
throw new DatabaseError('근태 기록 저장 중 데이터베이스 오류가 발생했습니다');
|
||||
}
|
||||
};
|
||||
@@ -173,28 +173,28 @@ const upsertAttendanceRecordService = async (recordData) => {
|
||||
* 휴가 처리
|
||||
*/
|
||||
const processVacationService = async (vacationData) => {
|
||||
const { record_date, worker_id, vacation_type_id } = vacationData;
|
||||
const { record_date, user_id, vacation_type_id } = vacationData;
|
||||
|
||||
if (!record_date || !worker_id || !vacation_type_id) {
|
||||
if (!record_date || !user_id || !vacation_type_id) {
|
||||
throw new ValidationError('필수 필드가 누락되었습니다', {
|
||||
required: ['record_date', 'worker_id', 'vacation_type_id'],
|
||||
received: { record_date, worker_id, vacation_type_id }
|
||||
required: ['record_date', 'user_id', 'vacation_type_id'],
|
||||
received: { record_date, user_id, vacation_type_id }
|
||||
});
|
||||
}
|
||||
|
||||
logger.info('휴가 처리 요청', { record_date, worker_id, vacation_type_id });
|
||||
logger.info('휴가 처리 요청', { record_date, user_id, vacation_type_id });
|
||||
|
||||
try {
|
||||
const result = await AttendanceModel.processVacation({
|
||||
record_date,
|
||||
worker_id,
|
||||
user_id,
|
||||
vacation_type_id
|
||||
});
|
||||
|
||||
logger.info('휴가 처리 성공', { record_date, worker_id });
|
||||
logger.info('휴가 처리 성공', { record_date, user_id });
|
||||
return result;
|
||||
} catch (error) {
|
||||
logger.error('휴가 처리 실패', { record_date, worker_id, error: error.message });
|
||||
logger.error('휴가 처리 실패', { record_date, user_id, error: error.message });
|
||||
throw new DatabaseError('휴가 처리 중 데이터베이스 오류가 발생했습니다');
|
||||
}
|
||||
};
|
||||
@@ -203,28 +203,28 @@ const processVacationService = async (vacationData) => {
|
||||
* 초과 근무 승인
|
||||
*/
|
||||
const approveOvertimeService = async (overtimeData) => {
|
||||
const { record_date, worker_id, overtime_approved } = overtimeData;
|
||||
const { record_date, user_id, overtime_approved } = overtimeData;
|
||||
|
||||
if (!record_date || !worker_id || overtime_approved === undefined) {
|
||||
if (!record_date || !user_id || overtime_approved === undefined) {
|
||||
throw new ValidationError('필수 필드가 누락되었습니다', {
|
||||
required: ['record_date', 'worker_id', 'overtime_approved'],
|
||||
received: { record_date, worker_id, overtime_approved }
|
||||
required: ['record_date', 'user_id', 'overtime_approved'],
|
||||
received: { record_date, user_id, overtime_approved }
|
||||
});
|
||||
}
|
||||
|
||||
logger.info('초과 근무 승인 요청', { record_date, worker_id, overtime_approved });
|
||||
logger.info('초과 근무 승인 요청', { record_date, user_id, overtime_approved });
|
||||
|
||||
try {
|
||||
const result = await AttendanceModel.approveOvertime({
|
||||
record_date,
|
||||
worker_id,
|
||||
user_id,
|
||||
overtime_approved
|
||||
});
|
||||
|
||||
logger.info('초과 근무 승인 처리 성공', { record_date, worker_id });
|
||||
logger.info('초과 근무 승인 처리 성공', { record_date, user_id });
|
||||
return result;
|
||||
} catch (error) {
|
||||
logger.error('초과 근무 승인 실패', { record_date, worker_id, error: error.message });
|
||||
logger.error('초과 근무 승인 실패', { record_date, user_id, error: error.message });
|
||||
throw new DatabaseError('초과 근무 승인 중 데이터베이스 오류가 발생했습니다');
|
||||
}
|
||||
};
|
||||
@@ -264,22 +264,22 @@ const getVacationTypesService = async () => {
|
||||
/**
|
||||
* 작업자 휴가 잔여 일수 조회
|
||||
*/
|
||||
const getWorkerVacationBalanceService = async (workerId) => {
|
||||
if (!workerId) {
|
||||
const getWorkerVacationBalanceService = async (userId) => {
|
||||
if (!userId) {
|
||||
throw new ValidationError('작업자 ID가 필요합니다', {
|
||||
required: ['worker_id'],
|
||||
received: { workerId }
|
||||
required: ['user_id'],
|
||||
received: { userId }
|
||||
});
|
||||
}
|
||||
|
||||
logger.info('휴가 잔여 일수 조회 요청', { workerId });
|
||||
logger.info('휴가 잔여 일수 조회 요청', { userId });
|
||||
|
||||
try {
|
||||
const balance = await AttendanceModel.getWorkerVacationBalance(workerId);
|
||||
logger.info('휴가 잔여 일수 조회 성공', { workerId });
|
||||
const balance = await AttendanceModel.getWorkerVacationBalance(userId);
|
||||
logger.info('휴가 잔여 일수 조회 성공', { userId });
|
||||
return balance;
|
||||
} catch (error) {
|
||||
logger.error('휴가 잔여 일수 조회 실패', { workerId, error: error.message });
|
||||
logger.error('휴가 잔여 일수 조회 실패', { userId, error: error.message });
|
||||
throw new DatabaseError('휴가 잔여 일수 조회 중 데이터베이스 오류가 발생했습니다');
|
||||
}
|
||||
};
|
||||
@@ -287,7 +287,7 @@ const getWorkerVacationBalanceService = async (workerId) => {
|
||||
/**
|
||||
* 월별 근태 통계 조회
|
||||
*/
|
||||
const getMonthlyAttendanceStatsService = async (year, month, workerId = null) => {
|
||||
const getMonthlyAttendanceStatsService = async (year, month, userId = null) => {
|
||||
if (!year || !month) {
|
||||
throw new ValidationError('연도와 월이 필요합니다', {
|
||||
required: ['year', 'month'],
|
||||
@@ -295,10 +295,10 @@ const getMonthlyAttendanceStatsService = async (year, month, workerId = null) =>
|
||||
});
|
||||
}
|
||||
|
||||
logger.info('월별 근태 통계 조회 요청', { year, month, workerId });
|
||||
logger.info('월별 근태 통계 조회 요청', { year, month, userId });
|
||||
|
||||
try {
|
||||
const stats = await AttendanceModel.getMonthlyAttendanceStats(year, month, workerId);
|
||||
const stats = await AttendanceModel.getMonthlyAttendanceStats(year, month, userId);
|
||||
logger.info('월별 근태 통계 조회 성공', { year, month });
|
||||
return stats;
|
||||
} catch (error) {
|
||||
@@ -347,21 +347,21 @@ const saveCheckinsService = async (date, checkins) => {
|
||||
const results = [];
|
||||
|
||||
for (const checkin of checkins) {
|
||||
const { worker_id, is_present } = checkin;
|
||||
const { user_id, is_present } = checkin;
|
||||
|
||||
if (!worker_id || is_present === undefined) {
|
||||
if (!user_id || is_present === undefined) {
|
||||
logger.warn('출근 체크 데이터 누락', { checkin });
|
||||
continue;
|
||||
}
|
||||
|
||||
const result = await AttendanceModel.upsertCheckin({
|
||||
worker_id,
|
||||
user_id,
|
||||
record_date: date,
|
||||
is_present
|
||||
});
|
||||
|
||||
results.push({
|
||||
worker_id,
|
||||
user_id,
|
||||
record_id: result,
|
||||
is_present
|
||||
});
|
||||
|
||||
@@ -57,7 +57,7 @@ const loginService = async (username, password, ipAddress, userAgent) => {
|
||||
|
||||
|
||||
const token = jwt.sign(
|
||||
{ user_id: user.user_id, username: user.username, role: user.role_name, role_id: user.role_id, access_level: user.access_level, worker_id: user.worker_id, name: user.name || user.username },
|
||||
{ user_id: user.user_id, username: user.username, role: user.role_name, role_id: user.role_id, access_level: user.access_level, name: user.name || user.username },
|
||||
process.env.JWT_SECRET || 'your-secret-key',
|
||||
{ expiresIn: process.env.JWT_EXPIRES_IN || '24h' }
|
||||
);
|
||||
@@ -81,8 +81,7 @@ const loginService = async (username, password, ipAddress, userAgent) => {
|
||||
username: user.username,
|
||||
name: user.name || user.username,
|
||||
role: user.role_name,
|
||||
access_level: user.access_level,
|
||||
worker_id: user.worker_id
|
||||
access_level: user.access_level
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -22,23 +22,23 @@ const logger = require('../utils/logger');
|
||||
* @param {string} issueData.start_time - 이슈 시작 시간
|
||||
* @param {string} issueData.end_time - 이슈 종료 시간
|
||||
* @param {number} issueData.issue_type_id - 이슈 유형 ID
|
||||
* @param {number[]} issueData.worker_ids - 작업자 ID 배열
|
||||
* @param {number[]} issueData.user_ids - 작업자 ID 배열
|
||||
* @returns {Promise<object>} 생성 결과
|
||||
*/
|
||||
const createDailyIssueReportService = async (issueData) => {
|
||||
const { date, project_id, start_time, end_time, issue_type_id, worker_ids } = issueData;
|
||||
const { date, project_id, start_time, end_time, issue_type_id, user_ids } = issueData;
|
||||
|
||||
// 필수 필드 검증
|
||||
if (!date || !project_id || !start_time || !end_time || !issue_type_id || !worker_ids) {
|
||||
if (!date || !project_id || !start_time || !end_time || !issue_type_id || !user_ids) {
|
||||
throw new ValidationError('필수 필드가 누락되었습니다', {
|
||||
required: ['date', 'project_id', 'start_time', 'end_time', 'issue_type_id', 'worker_ids'],
|
||||
received: { date, project_id, start_time, end_time, issue_type_id, worker_ids: !!worker_ids }
|
||||
required: ['date', 'project_id', 'start_time', 'end_time', 'issue_type_id', 'user_ids'],
|
||||
received: { date, project_id, start_time, end_time, issue_type_id, user_ids: !!user_ids }
|
||||
});
|
||||
}
|
||||
|
||||
if (!Array.isArray(worker_ids) || worker_ids.length === 0) {
|
||||
throw new ValidationError('worker_ids는 최소 한 명 이상의 작업자를 포함하는 배열이어야 합니다', {
|
||||
received: { worker_ids, isArray: Array.isArray(worker_ids), length: worker_ids?.length }
|
||||
if (!Array.isArray(user_ids) || user_ids.length === 0) {
|
||||
throw new ValidationError('user_ids는 최소 한 명 이상의 작업자를 포함하는 배열이어야 합니다', {
|
||||
received: { user_ids, isArray: Array.isArray(user_ids), length: user_ids?.length }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -46,17 +46,17 @@ const createDailyIssueReportService = async (issueData) => {
|
||||
date,
|
||||
project_id,
|
||||
issue_type_id,
|
||||
worker_count: worker_ids.length
|
||||
worker_count: user_ids.length
|
||||
});
|
||||
|
||||
// 모델에 전달할 데이터 준비
|
||||
const reportsToCreate = worker_ids.map(worker_id => ({
|
||||
const reportsToCreate = user_ids.map(user_id => ({
|
||||
date,
|
||||
project_id,
|
||||
start_time,
|
||||
end_time,
|
||||
issue_type_id,
|
||||
worker_id
|
||||
user_id
|
||||
}));
|
||||
|
||||
try {
|
||||
@@ -75,7 +75,7 @@ const createDailyIssueReportService = async (issueData) => {
|
||||
logger.error('이슈 보고서 생성 실패', {
|
||||
date,
|
||||
project_id,
|
||||
worker_ids,
|
||||
user_ids,
|
||||
error: error.message
|
||||
});
|
||||
throw new DatabaseError('이슈 보고서 생성 중 오류가 발생했습니다');
|
||||
|
||||
@@ -17,13 +17,13 @@ const logger = require('../utils/logger');
|
||||
* @returns {Promise<object>} 생성 결과 또는 에러
|
||||
*/
|
||||
const createDailyWorkReportService = async (reportData) => {
|
||||
const { report_date, worker_id, work_entries, created_by, created_by_name } = reportData;
|
||||
const { report_date, user_id, work_entries, created_by, created_by_name } = reportData;
|
||||
|
||||
// 1. 기본 유효성 검사
|
||||
if (!report_date || !worker_id || !work_entries) {
|
||||
if (!report_date || !user_id || !work_entries) {
|
||||
throw new ValidationError('필수 필드가 누락되었습니다', {
|
||||
required: ['report_date', 'worker_id', 'work_entries'],
|
||||
received: { report_date, worker_id, work_entries: !!work_entries }
|
||||
required: ['report_date', 'user_id', 'work_entries'],
|
||||
received: { report_date, user_id, work_entries: !!work_entries }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ const createDailyWorkReportService = async (reportData) => {
|
||||
// 3. 모델에 전달할 데이터 준비
|
||||
const modelData = {
|
||||
report_date,
|
||||
worker_id: parseInt(worker_id),
|
||||
user_id: parseInt(user_id),
|
||||
entries: work_entries.map(entry => ({
|
||||
project_id: entry.project_id,
|
||||
work_type_id: entry.task_id, // task_id를 work_type_id로 매핑
|
||||
@@ -83,7 +83,7 @@ const createDailyWorkReportService = async (reportData) => {
|
||||
|
||||
logger.info('작업보고서 생성 요청', {
|
||||
date: report_date,
|
||||
worker: worker_id,
|
||||
worker: user_id,
|
||||
creator: created_by_name,
|
||||
entries_count: modelData.entries.length
|
||||
});
|
||||
@@ -117,7 +117,7 @@ const createDailyWorkReportService = async (reportData) => {
|
||||
* @returns {Promise<Array>} 조회된 작업 보고서 배열
|
||||
*/
|
||||
const getDailyWorkReportsService = async (queryParams, userInfo) => {
|
||||
const { date, start_date, end_date, worker_id, created_by: requested_created_by, view_all } = queryParams;
|
||||
const { date, start_date, end_date, user_id, created_by: requested_created_by, view_all } = queryParams;
|
||||
const { user_id: current_user_id, role } = userInfo;
|
||||
|
||||
// 날짜 또는 날짜 범위 중 하나는 필수
|
||||
@@ -142,8 +142,8 @@ const getDailyWorkReportsService = async (queryParams, userInfo) => {
|
||||
options.end_date = end_date;
|
||||
}
|
||||
|
||||
if (worker_id) {
|
||||
options.worker_id = parseInt(worker_id);
|
||||
if (user_id) {
|
||||
options.user_id = parseInt(user_id);
|
||||
}
|
||||
|
||||
// 최종적으로 필터링할 작성자 ID 결정
|
||||
@@ -285,16 +285,16 @@ const getStatisticsService = async (queryParams) => {
|
||||
|
||||
/**
|
||||
* 일일 또는 작업자별 작업 요약 정보를 조회하는 비즈니스 로직을 처리합니다.
|
||||
* @param {object} queryParams - 컨트롤러에서 전달된 쿼리 파라미터 (date 또는 worker_id)
|
||||
* @param {object} queryParams - 컨트롤러에서 전달된 쿼리 파라미터 (date 또는 user_id)
|
||||
* @returns {Promise<object>} 요약 데이터
|
||||
*/
|
||||
const getSummaryService = async (queryParams) => {
|
||||
const { date, worker_id } = queryParams;
|
||||
const { date, user_id } = queryParams;
|
||||
|
||||
if (!date && !worker_id) {
|
||||
if (!date && !user_id) {
|
||||
throw new ValidationError('날짜 또는 작업자 ID가 필요합니다', {
|
||||
required: 'date OR worker_id',
|
||||
received: { date, worker_id }
|
||||
required: 'date OR user_id',
|
||||
received: { date, user_id }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -304,10 +304,10 @@ const getSummaryService = async (queryParams) => {
|
||||
const result = await dailyWorkReportModel.getSummaryByDate(date);
|
||||
logger.info('일일 요약 조회 성공', { date });
|
||||
return result;
|
||||
} else { // worker_id
|
||||
logger.info('작업자별 요약 조회 요청', { worker_id });
|
||||
const result = await dailyWorkReportModel.getSummaryByWorker(worker_id);
|
||||
logger.info('작업자별 요약 조회 성공', { worker_id });
|
||||
} else { // user_id
|
||||
logger.info('작업자별 요약 조회 요청', { user_id });
|
||||
const result = await dailyWorkReportModel.getSummaryByWorker(user_id);
|
||||
logger.info('작업자별 요약 조회 성공', { user_id });
|
||||
return result;
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user