feat: list + task endpoints and CORS, verified end-to-end
This commit is contained in:
20
server/api/tasks.post.ts
Normal file
20
server/api/tasks.post.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
// POST /api/tasks (web) — create an Idle task with a server-generated GUID.
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event);
|
||||
const title = typeof body?.title === "string" ? body.title.trim() : "";
|
||||
const listId = body?.listId;
|
||||
if (!title || typeof listId !== "string") {
|
||||
throw createError({ statusCode: 400, statusMessage: "title and listId are required" });
|
||||
}
|
||||
const description =
|
||||
typeof body?.description === "string" && body.description.trim() ? body.description : null;
|
||||
|
||||
const sql = getSql();
|
||||
if (!(await listExists(sql, listId))) {
|
||||
throw createError({ statusCode: 404, statusMessage: "list not found" });
|
||||
}
|
||||
|
||||
const row = await createWebTask(sql, { listId, title, description });
|
||||
setResponseStatus(event, 201);
|
||||
return toTaskDto(row);
|
||||
});
|
||||
Reference in New Issue
Block a user