import { insertReturning } from '../../utils/db' import { getCurrentUserId } from '../../utils/user' interface CreateTodoBody { todoTitle: string todoContent?: string sourceType?: string sourceId?: number meetingId?: number projectId?: number assigneeId?: number dueDate?: string priority?: number } /** * TODO 생성 * POST /api/todo/create */ export default defineEventHandler(async (event) => { const body = await readBody(event) const userId = await getCurrentUserId(event) if (!body.todoTitle?.trim()) { throw createError({ statusCode: 400, message: '제목을 입력해주세요.' }) } const result = await insertReturning(` INSERT INTO wr_todo ( todo_title, todo_content, source_type, source_id, meeting_id, project_id, assignee_id, reporter_id, due_date, status, priority, created_by ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, 'PENDING', $10, $8) RETURNING * `, [ body.todoTitle.trim(), body.todoContent || null, body.sourceType || null, body.sourceId || null, body.meetingId || null, body.projectId || null, body.assigneeId || null, userId, body.dueDate || null, body.priority || 1 ]) return { success: true, todo: { todoId: result.todo_id, todoTitle: result.todo_title, status: result.status } } })