// PUT /api/tasks/:id (desktop) — idempotent upsert mirroring a desktop Idle task, owned by the caller. export default defineEventHandler(async (event) => { const id = getRouterParam(event, "id")!; const body = await readBody(event); const title = body?.title; const listId = body?.listId; if (typeof title !== "string" || !title.trim() || typeof listId !== "string") { throw createError({ statusCode: 400, statusMessage: "listId and title are required" }); } const description = typeof body?.description === "string" ? body.description : null; const ownerId = ownerOf(event); const sql = getSql(); if (!(await listExists(sql, ownerId, listId))) { throw createError({ statusCode: 404, statusMessage: "list not found" }); } const { created } = await upsertDesktopTask(sql, ownerId, id, { listId, title, description }); setResponseStatus(event, created ? 201 : 200); return { id }; });