feat(11-01): PATCH /api/threads/:id/candidates/reorder route + tests

- Import reorderCandidatesSchema and reorderCandidates into threads route
- Add PATCH /:id/candidates/reorder route with Zod validation
- Returns 200 + { success: true } on active thread, 400 on resolved thread
- Add 5 route tests: success, order persists, resolved guard, empty array, missing field
This commit is contained in:
2026-03-16 22:22:31 +01:00
parent f01d71d6b4
commit d6acfcb126
2 changed files with 130 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import { Hono } from "hono";
import {
createCandidateSchema,
createThreadSchema,
reorderCandidatesSchema,
resolveThreadSchema,
updateCandidateSchema,
updateThreadSchema,
@@ -16,6 +17,7 @@ import {
deleteThread,
getAllThreads,
getThreadWithCandidates,
reorderCandidates,
resolveThread,
updateCandidate,
updateThread,
@@ -122,6 +124,21 @@ app.delete("/:threadId/candidates/:candidateId", async (c) => {
return c.json({ success: true });
});
// Candidate reorder
app.patch(
"/:id/candidates/reorder",
zValidator("json", reorderCandidatesSchema),
(c) => {
const db = c.get("db");
const threadId = Number(c.req.param("id"));
const { orderedIds } = c.req.valid("json");
const result = reorderCandidates(db, threadId, orderedIds);
if (!result.success) return c.json({ error: result.error }, 400);
return c.json({ success: true });
},
);
// Resolution
app.post("/:id/resolve", zValidator("json", resolveThreadSchema), (c) => {