feat: 일일순회점검 시스템 구축 및 관리 기능 개선
- 일일순회점검 시스템 신규 구현 - DB 테이블: patrol_checklist_items, daily_patrol_sessions, patrol_check_records, workplace_items, item_types - API: /api/patrol/* 엔드포인트 - 프론트엔드: 지도 기반 작업장 점검 UI - 설비 관리 기능 개선 - 구매 관련 필드 추가 (구매일, 가격, 공급업체 등) - 설비 코드 자동 생성 (TKP-XXX 형식) - 작업장 관리 개선 - 레이아웃 이미지 업로드 기능 - 마커 위치 저장 기능 - 부서 관리 기능 추가 - 사이드바 네비게이션 카테고리 재구성 - 이미지 401 오류 수정 (정적 파일 경로 처리) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -43,11 +43,17 @@ const getAllUsers = asyncHandler(async (req, res) => {
|
||||
r.name as role,
|
||||
u._access_level_old as access_level,
|
||||
u.is_active,
|
||||
u.worker_id,
|
||||
w.worker_name,
|
||||
w.department_id,
|
||||
d.department_name,
|
||||
u.created_at,
|
||||
u.updated_at,
|
||||
u.last_login_at as last_login
|
||||
FROM users u
|
||||
LEFT JOIN roles r ON u.role_id = r.id
|
||||
LEFT JOIN workers w ON u.worker_id = w.worker_id
|
||||
LEFT JOIN departments d ON w.department_id = d.department_id
|
||||
ORDER BY u.created_at DESC
|
||||
`;
|
||||
|
||||
@@ -218,7 +224,7 @@ const updateUser = asyncHandler(async (req, res) => {
|
||||
checkAdminPermission(req.user);
|
||||
|
||||
const { id } = req.params;
|
||||
const { username, name, email, role, role_id, password } = req.body;
|
||||
const { username, name, email, role, role_id, password, worker_id } = req.body;
|
||||
|
||||
if (!id || isNaN(id)) {
|
||||
throw new ValidationError('유효하지 않은 사용자 ID입니다');
|
||||
@@ -227,7 +233,7 @@ const updateUser = asyncHandler(async (req, res) => {
|
||||
logger.info('사용자 수정 요청', { userId: id, body: req.body });
|
||||
|
||||
// 최소 하나의 수정 필드가 필요
|
||||
if (!username && !name && email === undefined && !role && !role_id && !password) {
|
||||
if (!username && !name && email === undefined && !role && !role_id && !password && worker_id === undefined) {
|
||||
throw new ValidationError('수정할 필드가 없습니다');
|
||||
}
|
||||
|
||||
@@ -318,6 +324,22 @@ const updateUser = asyncHandler(async (req, res) => {
|
||||
values.push(hashedPassword);
|
||||
}
|
||||
|
||||
// worker_id 업데이트 (null도 허용 - 연결 해제)
|
||||
if (worker_id !== undefined) {
|
||||
if (worker_id !== null) {
|
||||
// worker_id가 유효한지 확인
|
||||
const [workerCheck] = await db.execute('SELECT worker_id, worker_name FROM workers WHERE worker_id = ?', [worker_id]);
|
||||
if (workerCheck.length === 0) {
|
||||
throw new ValidationError('유효하지 않은 작업자 ID입니다');
|
||||
}
|
||||
logger.info('작업자 연결', { userId: id, worker_id, worker_name: workerCheck[0].worker_name });
|
||||
} else {
|
||||
logger.info('작업자 연결 해제', { userId: id });
|
||||
}
|
||||
updates.push('worker_id = ?');
|
||||
values.push(worker_id);
|
||||
}
|
||||
|
||||
updates.push('updated_at = NOW()');
|
||||
values.push(id);
|
||||
|
||||
@@ -476,6 +498,69 @@ const deleteUser = asyncHandler(async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 사용자 영구 삭제 (Hard Delete)
|
||||
*/
|
||||
const permanentDeleteUser = asyncHandler(async (req, res) => {
|
||||
checkAdminPermission(req.user);
|
||||
|
||||
const { id } = req.params;
|
||||
|
||||
if (!id || isNaN(id)) {
|
||||
throw new ValidationError('유효하지 않은 사용자 ID입니다');
|
||||
}
|
||||
|
||||
// 자기 자신 삭제 방지
|
||||
if (req.user && req.user.user_id == id) {
|
||||
throw new ValidationError('자기 자신은 삭제할 수 없습니다');
|
||||
}
|
||||
|
||||
logger.info('사용자 영구 삭제 요청', { userId: id });
|
||||
|
||||
const { getDb } = require('../dbPool');
|
||||
const db = await getDb();
|
||||
|
||||
try {
|
||||
// 사용자 존재 확인
|
||||
const checkQuery = 'SELECT user_id, username FROM users WHERE user_id = ?';
|
||||
const [users] = await db.execute(checkQuery, [id]);
|
||||
|
||||
if (users.length === 0) {
|
||||
throw new NotFoundError('사용자를 찾을 수 없습니다');
|
||||
}
|
||||
|
||||
const username = users[0].username;
|
||||
|
||||
// 관련 데이터 삭제 (외래 키 제약 조건 때문에 순서 중요)
|
||||
// 1. 로그인 로그 삭제
|
||||
await db.execute('DELETE FROM login_logs WHERE user_id = ?', [id]);
|
||||
|
||||
// 2. 페이지 접근 권한 삭제
|
||||
await db.execute('DELETE FROM user_page_access WHERE user_id = ?', [id]);
|
||||
|
||||
// 3. 사용자 삭제
|
||||
await db.execute('DELETE FROM users WHERE user_id = ?', [id]);
|
||||
|
||||
logger.info('사용자 영구 삭제 성공', {
|
||||
userId: id,
|
||||
username: username,
|
||||
deletedBy: req.user.username
|
||||
});
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
data: { user_id: id },
|
||||
message: `사용자 "${username}"이(가) 영구적으로 삭제되었습니다`
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof NotFoundError || error instanceof ValidationError) {
|
||||
throw error;
|
||||
}
|
||||
logger.error('사용자 영구 삭제 실패', { userId: id, error: error.message });
|
||||
throw new DatabaseError('사용자를 영구 삭제하는데 실패했습니다');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 사용자의 페이지 접근 권한 조회
|
||||
*/
|
||||
@@ -647,6 +732,7 @@ module.exports = {
|
||||
updateUser,
|
||||
updateUserStatus,
|
||||
deleteUser,
|
||||
permanentDeleteUser,
|
||||
getUserPageAccess,
|
||||
updateUserPageAccess,
|
||||
resetUserPassword
|
||||
|
||||
Reference in New Issue
Block a user