Files
weeklyreport/backend/api/maintenance/[id]/update.put.ts

86 lines
2.2 KiB
TypeScript

import { queryOne, execute } from '../../../utils/db'
import { getCurrentUserId } from '../../../utils/user'
interface UpdateMaintenanceBody {
projectId?: number | null
requestDate?: string
requestTitle?: string
requestContent?: string
requesterName?: string
requesterContact?: string
taskType?: string
priority?: string
status?: string
assigneeId?: number | null
resolutionContent?: string
devCompletedAt?: string | null
opsCompletedAt?: string | null
clientConfirmedAt?: string | null
}
/**
* 유지보수 업무 수정
* PUT /api/maintenance/[id]/update
*/
export default defineEventHandler(async (event) => {
const taskId = Number(getRouterParam(event, 'id'))
const body = await readBody<UpdateMaintenanceBody>(event)
const userId = await getCurrentUserId(event)
if (!taskId) {
throw createError({ statusCode: 400, message: '업무 ID가 필요합니다.' })
}
const existing = await queryOne(`
SELECT task_id FROM wr_maintenance_task WHERE task_id = $1
`, [taskId])
if (!existing) {
throw createError({ statusCode: 404, message: '업무를 찾을 수 없습니다.' })
}
await execute(`
UPDATE wr_maintenance_task SET
project_id = $1,
request_date = $2,
request_title = $3,
request_content = $4,
requester_name = $5,
requester_contact = $6,
task_type = $7,
priority = $8,
status = $9,
assignee_id = $10,
resolution_content = $11,
dev_completed_at = $12,
ops_completed_at = $13,
client_confirmed_at = $14,
updated_at = NOW(),
updated_by = $15
WHERE task_id = $16
`, [
body.projectId ?? null,
body.requestDate,
body.requestTitle,
body.requestContent || null,
body.requesterName || null,
body.requesterContact || null,
body.taskType || 'GENERAL',
body.priority || 'MEDIUM',
body.status || 'PENDING',
body.assigneeId ?? null,
body.resolutionContent || null,
body.devCompletedAt || null,
body.opsCompletedAt || null,
body.clientConfirmedAt || null,
userId,
taskId
])
return {
success: true,
taskId,
message: '유지보수 업무가 수정되었습니다.'
}
})