기능구현중
This commit is contained in:
44
server/api/business/[id]/delete.delete.ts
Normal file
44
server/api/business/[id]/delete.delete.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
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: '사업이 삭제(중단) 처리되었습니다.'
|
||||
}
|
||||
})
|
||||
71
server/api/business/[id]/detail.get.ts
Normal file
71
server/api/business/[id]/detail.get.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { query, queryOne } from '../../../utils/db'
|
||||
|
||||
/**
|
||||
* 사업 상세 조회
|
||||
* GET /api/business/[id]/detail
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const businessId = Number(getRouterParam(event, 'id'))
|
||||
|
||||
if (!businessId) {
|
||||
throw createError({ statusCode: 400, message: '사업 ID가 필요합니다.' })
|
||||
}
|
||||
|
||||
const business = await queryOne(`
|
||||
SELECT
|
||||
b.*,
|
||||
e1.employee_name as created_by_name,
|
||||
e2.employee_name as updated_by_name
|
||||
FROM wr_business b
|
||||
LEFT JOIN wr_employee_info e1 ON b.created_by = e1.employee_id
|
||||
LEFT JOIN wr_employee_info e2 ON b.updated_by = e2.employee_id
|
||||
WHERE b.business_id = $1
|
||||
`, [businessId])
|
||||
|
||||
if (!business) {
|
||||
throw createError({ statusCode: 404, message: '사업을 찾을 수 없습니다.' })
|
||||
}
|
||||
|
||||
// 소속 프로젝트 목록
|
||||
const projects = await query(`
|
||||
SELECT
|
||||
p.project_id,
|
||||
p.project_name,
|
||||
p.project_code,
|
||||
p.project_type,
|
||||
p.project_status,
|
||||
p.start_date,
|
||||
p.end_date
|
||||
FROM wr_project_info p
|
||||
WHERE p.business_id = $1
|
||||
ORDER BY p.project_name
|
||||
`, [businessId])
|
||||
|
||||
return {
|
||||
business: {
|
||||
businessId: business.business_id,
|
||||
businessName: business.business_name,
|
||||
businessCode: business.business_code,
|
||||
clientName: business.client_name,
|
||||
contractStartDate: business.contract_start_date,
|
||||
contractEndDate: business.contract_end_date,
|
||||
businessStatus: business.business_status,
|
||||
description: business.description,
|
||||
createdBy: business.created_by,
|
||||
createdByName: business.created_by_name,
|
||||
updatedBy: business.updated_by,
|
||||
updatedByName: business.updated_by_name,
|
||||
createdAt: business.created_at,
|
||||
updatedAt: business.updated_at
|
||||
},
|
||||
projects: projects.map((p: any) => ({
|
||||
projectId: p.project_id,
|
||||
projectName: p.project_name,
|
||||
projectCode: p.project_code,
|
||||
projectType: p.project_type,
|
||||
projectStatus: p.project_status,
|
||||
startDate: p.start_date,
|
||||
endDate: p.end_date
|
||||
}))
|
||||
}
|
||||
})
|
||||
68
server/api/business/[id]/update.put.ts
Normal file
68
server/api/business/[id]/update.put.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { queryOne, execute } from '../../../utils/db'
|
||||
import { getCurrentUserId } from '../../../utils/user'
|
||||
|
||||
interface UpdateBusinessBody {
|
||||
businessName: string
|
||||
businessCode?: string
|
||||
clientName?: string
|
||||
contractStartDate?: string
|
||||
contractEndDate?: string
|
||||
businessStatus?: string
|
||||
description?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 사업 수정
|
||||
* PUT /api/business/[id]/update
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const businessId = Number(getRouterParam(event, 'id'))
|
||||
const body = await readBody<UpdateBusinessBody>(event)
|
||||
const userId = await getCurrentUserId(event)
|
||||
|
||||
if (!businessId) {
|
||||
throw createError({ statusCode: 400, message: '사업 ID가 필요합니다.' })
|
||||
}
|
||||
|
||||
if (!body.businessName) {
|
||||
throw createError({ statusCode: 400, message: '사업명은 필수입니다.' })
|
||||
}
|
||||
|
||||
const existing = await queryOne(`
|
||||
SELECT business_id FROM wr_business WHERE business_id = $1
|
||||
`, [businessId])
|
||||
|
||||
if (!existing) {
|
||||
throw createError({ statusCode: 404, message: '사업을 찾을 수 없습니다.' })
|
||||
}
|
||||
|
||||
await execute(`
|
||||
UPDATE wr_business SET
|
||||
business_name = $1,
|
||||
business_code = $2,
|
||||
client_name = $3,
|
||||
contract_start_date = $4,
|
||||
contract_end_date = $5,
|
||||
business_status = $6,
|
||||
description = $7,
|
||||
updated_at = NOW(),
|
||||
updated_by = $8
|
||||
WHERE business_id = $9
|
||||
`, [
|
||||
body.businessName,
|
||||
body.businessCode || null,
|
||||
body.clientName || null,
|
||||
body.contractStartDate || null,
|
||||
body.contractEndDate || null,
|
||||
body.businessStatus || 'active',
|
||||
body.description || null,
|
||||
userId,
|
||||
businessId
|
||||
])
|
||||
|
||||
return {
|
||||
success: true,
|
||||
businessId,
|
||||
message: '사업이 수정되었습니다.'
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user