58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import { insertReturning } from '../../utils/db'
|
|
import { getCurrentUserId } from '../../utils/user'
|
|
|
|
interface CreateMaintenanceBody {
|
|
projectId?: number
|
|
requestDate: string
|
|
requestTitle: string
|
|
requestContent?: string
|
|
requesterName?: string
|
|
requesterContact?: string
|
|
taskType?: string
|
|
priority?: string
|
|
assigneeId?: number
|
|
}
|
|
|
|
/**
|
|
* 유지보수 업무 생성
|
|
* POST /api/maintenance/create
|
|
*/
|
|
export default defineEventHandler(async (event) => {
|
|
const body = await readBody<CreateMaintenanceBody>(event)
|
|
const userId = await getCurrentUserId(event)
|
|
|
|
if (!body.requestTitle) {
|
|
throw createError({ statusCode: 400, message: '제목은 필수입니다.' })
|
|
}
|
|
|
|
if (!body.requestDate) {
|
|
throw createError({ statusCode: 400, message: '요청일은 필수입니다.' })
|
|
}
|
|
|
|
const task = await insertReturning(`
|
|
INSERT INTO wr_maintenance_task (
|
|
project_id, request_date, request_title, request_content,
|
|
requester_name, requester_contact, task_type, priority,
|
|
assignee_id, status, created_by, updated_by
|
|
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, 'PENDING', $10, $10)
|
|
RETURNING *
|
|
`, [
|
|
body.projectId || null,
|
|
body.requestDate,
|
|
body.requestTitle,
|
|
body.requestContent || null,
|
|
body.requesterName || null,
|
|
body.requesterContact || null,
|
|
body.taskType || 'GENERAL',
|
|
body.priority || 'MEDIUM',
|
|
body.assigneeId || null,
|
|
userId
|
|
])
|
|
|
|
return {
|
|
success: true,
|
|
taskId: task.task_id,
|
|
message: '유지보수 업무가 등록되었습니다.'
|
|
}
|
|
})
|