feat: list + task endpoints and CORS, verified end-to-end
This commit is contained in:
20
server/api/tasks/[id].put.ts
Normal file
20
server/api/tasks/[id].put.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
// 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 };
|
||||
});
|
||||
Reference in New Issue
Block a user