45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { queryOne, execute } from '../../../utils/db'
|
|
|
|
/**
|
|
* 사업 삭제 (상태를 suspended로 변경)
|
|
* DELETE /api/business/[id]/delete
|
|
*/
|
|
export default defineEventHandler(async (event) => {
|
|
const businessId = Number(getRouterParam(event, 'id'))
|
|
|
|
if (!businessId) {
|
|
throw createError({ statusCode: 400, message: '사업 ID가 필요합니다.' })
|
|
}
|
|
|
|
const existing = await queryOne(`
|
|
SELECT business_id FROM wr_business WHERE business_id = $1
|
|
`, [businessId])
|
|
|
|
if (!existing) {
|
|
throw createError({ statusCode: 404, message: '사업을 찾을 수 없습니다.' })
|
|
}
|
|
|
|
// 소속 프로젝트 체크
|
|
const projectCount = await queryOne(`
|
|
SELECT COUNT(*) as cnt FROM wr_project_info WHERE business_id = $1
|
|
`, [businessId])
|
|
|
|
if (Number(projectCount?.cnt) > 0) {
|
|
throw createError({
|
|
statusCode: 400,
|
|
message: `소속된 프로젝트가 ${projectCount.cnt}개 있습니다. 먼저 프로젝트를 해제하세요.`
|
|
})
|
|
}
|
|
|
|
// 완전 삭제 대신 상태 변경
|
|
await execute(`
|
|
UPDATE wr_business SET business_status = 'suspended', updated_at = NOW()
|
|
WHERE business_id = $1
|
|
`, [businessId])
|
|
|
|
return {
|
|
success: true,
|
|
message: '사업이 삭제(중단) 처리되었습니다.'
|
|
}
|
|
})
|