69 lines
2.0 KiB
TypeScript
69 lines
2.0 KiB
TypeScript
import { execute, queryOne } from '../../../utils/db'
|
|
import { getClientIp } from '../../../utils/ip'
|
|
import { getCurrentUserEmail } from '../../../utils/user'
|
|
|
|
interface UpdateProjectBody {
|
|
projectName?: string
|
|
projectType?: string
|
|
clientName?: string
|
|
projectDescription?: string
|
|
startDate?: string
|
|
endDate?: string
|
|
contractAmount?: number
|
|
projectStatus?: string
|
|
}
|
|
|
|
/**
|
|
* 프로젝트 정보 수정
|
|
* PUT /api/project/[id]/update
|
|
*/
|
|
export default defineEventHandler(async (event) => {
|
|
const projectId = getRouterParam(event, 'id')
|
|
const body = await readBody<UpdateProjectBody>(event)
|
|
const clientIp = getClientIp(event)
|
|
const userEmail = await getCurrentUserEmail(event)
|
|
|
|
const existing = await queryOne<any>(`
|
|
SELECT * FROM wr_project_info WHERE project_id = $1
|
|
`, [projectId])
|
|
|
|
if (!existing) {
|
|
throw createError({ statusCode: 404, message: '프로젝트를 찾을 수 없습니다.' })
|
|
}
|
|
|
|
// 프로젝트 유형 검증
|
|
if (body.projectType && !['SI', 'SM'].includes(body.projectType)) {
|
|
throw createError({ statusCode: 400, message: '프로젝트 유형은 SI 또는 SM이어야 합니다.' })
|
|
}
|
|
|
|
await execute(`
|
|
UPDATE wr_project_info SET
|
|
project_name = $1,
|
|
project_type = $2,
|
|
client_name = $3,
|
|
project_description = $4,
|
|
start_date = $5,
|
|
end_date = $6,
|
|
contract_amount = $7,
|
|
project_status = $8,
|
|
updated_at = NOW(),
|
|
updated_ip = $9,
|
|
updated_email = $10
|
|
WHERE project_id = $11
|
|
`, [
|
|
body.projectName ?? existing.project_name,
|
|
body.projectType ?? existing.project_type ?? 'SI',
|
|
body.clientName ?? existing.client_name,
|
|
body.projectDescription ?? existing.project_description,
|
|
body.startDate ?? existing.start_date,
|
|
body.endDate ?? existing.end_date,
|
|
body.contractAmount ?? existing.contract_amount,
|
|
body.projectStatus ?? existing.project_status,
|
|
clientIp,
|
|
userEmail,
|
|
projectId
|
|
])
|
|
|
|
return { success: true }
|
|
})
|