import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi"; import { apiHit } from "../../../globalUtils/apiHits.js"; import { responses } from "../../../globalUtils/routeDefs/responses.js"; import { tryCatch } from "../../../globalUtils/tryCatch.js"; import { getInhouseDeliveryByDateRange } from "../controller/getInhouseDeliveryByDateRange.js"; const app = new OpenAPIHono({ strict: false }); const Body = z.object({ includeRunnningNumbers: z.string().openapi({ example: "x" }), }); app.openapi( createRoute({ tags: ["dataMart"], summary: "Returns deliveries by date range.", method: "get", path: "/inhousedeliverybydaterange", request: { body: { content: { "application/json": { schema: Body }, }, }, }, responses: responses(), }), async (c) => { const delivery: any = c.req.queries(); // make sure we have a vaid user being accessed thats really logged in apiHit(c, { endpoint: "/inhousedeliverybydaterange" }); const { data, error } = await tryCatch( getInhouseDeliveryByDateRange(delivery ? delivery : null), ); if (error) { console.log(error); return c.json( { success: false, message: "There was an error getting the deliveries.", data: error, }, 400, ); } return c.json({ success: data.success, message: data.message, data: data.data, }); }, ); export default app;