Files
TK-FB-Project/deploy/tkfb-package/api.hyungi.net/controllers/projectController.js
Hyungi Ahn 2b1c7bfb88 feat: 다수 기능 개선 - 순찰, 출근, 작업분석, 모바일 UI 등
- 순찰/점검 기능 개선 (zone-detail 페이지 추가)
- 출근/근태 시스템 개선 (연차 조회, 근무현황)
- 작업분석 대분류 그룹화 및 마이그레이션 스크립트
- 모바일 네비게이션 UI 추가
- NAS 배포 도구 및 문서 추가

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 14:41:01 +09:00

143 lines
3.3 KiB
JavaScript

/**
* 프로젝트 관리 컨트롤러
*
* 프로젝트 CRUD API 엔드포인트 핸들러
*
* @author TK-FB-Project
* @since 2025-12-11
*/
const projectModel = require('../models/projectModel');
const { ValidationError, NotFoundError, DatabaseError } = require('../utils/errors');
const { asyncHandler } = require('../middlewares/errorHandler');
const logger = require('../utils/logger');
const cache = require('../utils/cache');
/**
* 프로젝트 생성
*/
exports.createProject = asyncHandler(async (req, res) => {
const projectData = req.body;
logger.info('프로젝트 생성 요청', { name: projectData.name });
const id = await projectModel.create(projectData);
// 프로젝트 캐시 무효화
await cache.invalidateCache.project();
logger.info('프로젝트 생성 성공', { project_id: id });
res.status(201).json({
success: true,
data: { project_id: id },
message: '프로젝트가 성공적으로 생성되었습니다'
});
});
/**
* 전체 프로젝트 조회
*/
exports.getAllProjects = asyncHandler(async (req, res) => {
const rows = await projectModel.getAll();
res.json({
success: true,
data: rows,
message: '프로젝트 목록 조회 성공'
});
});
/**
* 활성 프로젝트만 조회 (작업보고서용)
*/
exports.getActiveProjects = asyncHandler(async (req, res) => {
const rows = await projectModel.getActiveProjects();
res.json({
success: true,
data: rows,
message: '활성 프로젝트 목록 조회 성공'
});
});
/**
* 단일 프로젝트 조회
*/
exports.getProjectById = asyncHandler(async (req, res) => {
const id = parseInt(req.params.project_id, 10);
if (isNaN(id)) {
throw new ValidationError('유효하지 않은 프로젝트 ID입니다');
}
const row = await projectModel.getById(id);
if (!row) {
throw new NotFoundError('프로젝트를 찾을 수 없습니다');
}
res.json({
success: true,
data: row,
message: '프로젝트 조회 성공'
});
});
/**
* 프로젝트 수정
*/
exports.updateProject = asyncHandler(async (req, res) => {
const id = parseInt(req.params.project_id, 10);
if (isNaN(id)) {
throw new ValidationError('유효하지 않은 프로젝트 ID입니다');
}
const data = { ...req.body, project_id: id };
const changes = await projectModel.update(data);
if (changes === 0) {
throw new NotFoundError('프로젝트를 찾을 수 없습니다');
}
// 프로젝트 캐시 무효화
await cache.invalidateCache.project();
logger.info('프로젝트 수정 성공', { project_id: id });
res.json({
success: true,
data: { changes },
message: '프로젝트 정보가 성공적으로 수정되었습니다'
});
});
/**
* 프로젝트 삭제
*/
exports.removeProject = asyncHandler(async (req, res) => {
const id = parseInt(req.params.project_id, 10);
if (isNaN(id)) {
throw new ValidationError('유효하지 않은 프로젝트 ID입니다');
}
const changes = await projectModel.remove(id);
if (changes === 0) {
throw new NotFoundError('프로젝트를 찾을 수 없습니다');
}
// 프로젝트 캐시 무효화
await cache.invalidateCache.project();
logger.info('프로젝트 삭제 성공', { project_id: id });
res.json({
success: true,
message: '프로젝트가 성공적으로 삭제되었습니다'
});
});