36 lines
926 B
TypeScript

import { Hono } from "hono";
import { getQaTasks, toggleQaTask } from "../db/qa.ts";
export const qaRoutes = new Hono();
qaRoutes.get("/", async (c) => {
try {
const tasks = await getQaTasks();
return c.json(tasks);
} catch (error: any) {
return c.json({ error: error.message }, 500);
}
});
qaRoutes.put("/:id", async (c) => {
const id = c.req.param("id");
let body: any;
try {
body = await c.req.json();
} catch {
return c.json({ error: "Invalid JSON payload" }, 400);
}
if (!body || typeof body.is_completed !== "boolean") {
return c.json({ error: "Invalid payload: 'is_completed' must be a boolean" }, 400);
}
try {
const updated = await toggleQaTask(id, body.is_completed);
if (updated.length === 0) return c.json({ error: "Task not found" }, 404);
return c.json(updated[0]);
} catch (error: any) {
return c.json({ error: error.message }, 500);
}
});