feat(19-02): add catalog-linked candidates, branched resolution, remove link/unlink routes

- getThreadWithCandidates LEFT JOINs globalItems with COALESCE for name, weight, price, image
- createCandidate accepts and stores globalItemId
- resolveThread branches: reference item (globalItemId set) vs standalone (full data copy)
- Removed link/unlink endpoints from items route (replaced by direct globalItemId FK)
- 6 new tests for catalog-linked candidates and branched resolution
This commit is contained in:
2026-04-05 20:49:56 +02:00
parent d1ffd79bbb
commit 8a5ee731d0
3 changed files with 210 additions and 45 deletions

View File

@@ -1,16 +1,8 @@
import { zValidator } from "@hono/zod-validator";
import { Hono } from "hono";
import {
createItemSchema,
linkItemSchema,
updateItemSchema,
} from "../../shared/schemas.ts";
import { createItemSchema, updateItemSchema } from "../../shared/schemas.ts";
import { parseId } from "../lib/params.ts";
import { exportItemsCsv, importItemsCsv } from "../services/csv.service.ts";
import {
linkItemToGlobal,
unlinkItemFromGlobal,
} from "../services/global-item.service.ts";
import {
createItem,
deleteItem,
@@ -122,32 +114,5 @@ app.delete("/:id", async (c) => {
return c.json({ success: true });
});
app.post("/:id/link", zValidator("json", linkItemSchema), (c) => {
const db = c.get("db");
const id = parseId(c.req.param("id"));
if (!id) return c.json({ error: "Invalid item ID" }, 400);
const item = getItemById(db, id);
if (!item) return c.json({ error: "Item not found" }, 404);
try {
const link = linkItemToGlobal(db, id, c.req.valid("json").globalItemId);
return c.json(link, 201);
} catch {
return c.json({ error: "Item already linked to a global item" }, 409);
}
});
app.delete("/:id/link", (c) => {
const db = c.get("db");
const id = parseId(c.req.param("id"));
if (!id) return c.json({ error: "Invalid item ID" }, 400);
const item = getItemById(db, id);
if (!item) return c.json({ error: "Item not found" }, 404);
unlinkItemFromGlobal(db, id);
return c.json({ success: true });
});
export { app as itemRoutes };