21 lines
851 B
TypeScript
21 lines
851 B
TypeScript
// PUT /api/tasks/:id (desktop) — idempotent upsert mirroring a desktop Idle task.
|
|
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 sql = getSql();
|
|
if (!(await listExists(sql, listId))) {
|
|
throw createError({ statusCode: 404, statusMessage: "list not found" });
|
|
}
|
|
|
|
const { created } = await upsertDesktopTask(sql, id, { listId, title, description });
|
|
setResponseStatus(event, created ? 201 : 200);
|
|
return { id };
|
|
});
|