import { queryOne, execute } from '../../../utils/db' import { getCurrentUserId } from '../../../utils/user' interface StatusBody { status: string } /** * 유지보수 업무 상태 변경 * PUT /api/maintenance/[id]/status */ export default defineEventHandler(async (event) => { const taskId = Number(getRouterParam(event, 'id')) const body = await readBody(event) const userId = await getCurrentUserId(event) if (!taskId) { throw createError({ statusCode: 400, message: '업무 ID가 필요합니다.' }) } const validStatuses = ['PENDING', 'IN_PROGRESS', 'COMPLETED'] if (!validStatuses.includes(body.status)) { throw createError({ statusCode: 400, message: '유효하지 않은 상태입니다.' }) } 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 status = $1, updated_at = NOW(), updated_by = $2 WHERE task_id = $3 `, [body.status, userId, taskId]) return { success: true, taskId, status: body.status, message: '상태가 변경되었습니다.' } })