diff --git a/src/server/routes/global-items.ts b/src/server/routes/global-items.ts index 2831ba6..529969a 100644 --- a/src/server/routes/global-items.ts +++ b/src/server/routes/global-items.ts @@ -1,8 +1,15 @@ +import { zValidator } from "@hono/zod-validator"; import { Hono } from "hono"; +import { + bulkUpsertGlobalItemsSchema, + upsertGlobalItemSchema, +} from "../../shared/schemas.ts"; import { parseId } from "../lib/params.ts"; import { + bulkUpsertGlobalItems, getGlobalItemWithOwnerCount, searchGlobalItems, + upsertGlobalItem, } from "../services/global-item.service.ts"; type Env = { Variables: { db?: any } }; @@ -32,4 +39,20 @@ app.get("/:id", async (c) => { return c.json(item); }); +// Single item upsert — per D-10 +app.post("/", zValidator("json", upsertGlobalItemSchema), async (c) => { + const db = c.get("db"); + const data = c.req.valid("json"); + const result = await upsertGlobalItem(db, data); + return c.json(result); +}); + +// Bulk upsert — per D-06, D-07, D-08 +app.post("/bulk", zValidator("json", bulkUpsertGlobalItemsSchema), async (c) => { + const db = c.get("db"); + const { items } = c.req.valid("json"); + const result = await bulkUpsertGlobalItems(db, items); + return c.json(result); +}); + export { app as globalItemRoutes };