refactor: API 서버 구조 개선 및 표준화

- 통합 에러 처리 시스템 구축:
  * utils/errorHandler.js: ApiError 클래스 및 에러 미들웨어
  * 데이터베이스, 유효성 검사, 권한 에러 표준화
  * 비동기 함수 래퍼 (asyncHandler) 추가

- 응답 포맷터 시스템 구축:
  * utils/responseFormatter.js: 일관된 API 응답 형식
  * 성공, 페이지네이션, 인증, 파일업로드 등 전용 포맷터
  * Express 응답 확장 미들웨어

- 유효성 검사 시스템 구축:
  * utils/validator.js: 스키마 기반 유효성 검사
  * 필수 필드, 타입, 길이, 형식 검사 함수들
  * 일반적인 스키마 정의 (사용자, 프로젝트, 작업보고서 등)

- 코드 정리 및 표준화:
  * 삭제된 테이블 참조 제거 (work_report_audit_log 등)
  * 대문자 테이블명을 소문자로 통일 (Users -> users)
  * authController.js에 새로운 유틸리티 적용 예시

- 미들웨어 통합:
  * index.js에 에러 핸들러 및 응답 포맷터 적용
  * 헬스체크 엔드포인트 개선
This commit is contained in:
Hyungi Ahn
2025-11-03 10:42:29 +09:00
parent 31e941cfbd
commit 4716434d65
8 changed files with 720 additions and 105 deletions

View File

@@ -786,7 +786,7 @@ router.delete('/users/:id', verifyToken, async (req, res) => {
// 사용자 존재 확인
const [existing] = await connection.execute(
'SELECT username FROM Users WHERE user_id = ?',
'SELECT username FROM users WHERE user_id = ?',
[userId]
);
@@ -799,12 +799,12 @@ router.delete('/users/:id', verifyToken, async (req, res) => {
// 소프트 삭제 (실제로는 비활성화)
await connection.execute(
'UPDATE Users SET is_active = FALSE, updated_at = NOW() WHERE user_id = ?',
'UPDATE users SET is_active = FALSE, updated_at = NOW() WHERE user_id = ?',
[userId]
);
// 또는 하드 삭제 (실제로 삭제)
// await connection.execute('DELETE FROM Users WHERE user_id = ?', [userId]);
// await connection.execute('DELETE FROM users WHERE user_id = ?', [userId]);
console.log(`[사용자 삭제] 대상: ${existing[0].username} - 삭제자: ${req.user.username}`);