feat(25-02): add POST single and bulk upsert routes for global items

- POST /api/global-items upserts single item via upsertGlobalItem service
- POST /api/global-items/bulk upserts up to 100 items via bulkUpsertGlobalItems service
- Zod validation via @hono/zod-validator with upsertGlobalItemSchema and bulkUpsertGlobalItemsSchema
This commit is contained in:
2026-04-10 11:02:49 +02:00
parent 25f590247c
commit 6491615b1d

View File

@@ -1,8 +1,15 @@
import { zValidator } from "@hono/zod-validator";
import { Hono } from "hono"; import { Hono } from "hono";
import {
bulkUpsertGlobalItemsSchema,
upsertGlobalItemSchema,
} from "../../shared/schemas.ts";
import { parseId } from "../lib/params.ts"; import { parseId } from "../lib/params.ts";
import { import {
bulkUpsertGlobalItems,
getGlobalItemWithOwnerCount, getGlobalItemWithOwnerCount,
searchGlobalItems, searchGlobalItems,
upsertGlobalItem,
} from "../services/global-item.service.ts"; } from "../services/global-item.service.ts";
type Env = { Variables: { db?: any } }; type Env = { Variables: { db?: any } };
@@ -32,4 +39,20 @@ app.get("/:id", async (c) => {
return c.json(item); 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 }; export { app as globalItemRoutes };