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:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user