67 lines
2.2 KiB
TypeScript
67 lines
2.2 KiB
TypeScript
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
|
import { lanesToExcel } from "../controller/warehouse/cycleCountChecks/exportCycleCountData.js";
|
|
import { format } from "date-fns";
|
|
|
|
const app = new OpenAPIHono();
|
|
|
|
// const Body = z
|
|
// .object({
|
|
// age: z.number().optional().openapi({ example: 90 }),
|
|
// //email: z.string().optional().openapi({example: "s.smith@example.com"}),
|
|
// type: z.string().optional().openapi({ example: "fg" }),
|
|
// })
|
|
// .openapi("User");
|
|
app.openapi(
|
|
createRoute({
|
|
tags: ["logistics"],
|
|
summary: "Returns the lanes that need to be counted",
|
|
method: "get",
|
|
path: "/getcyclecount",
|
|
// request: {
|
|
// body: {
|
|
// content: {
|
|
// "application/json": { schema: Body },
|
|
// },
|
|
// },
|
|
// },
|
|
// description:
|
|
// "Provided a running number and lot number you can consume material.",
|
|
responses: responses(),
|
|
}),
|
|
async (c: any) => {
|
|
//apiHit(c, { endpoint: "api/sqlProd/close" });
|
|
const defaultFilename = `cycleCount-${format(
|
|
new Date(Date.now()),
|
|
"M-d-yyyy"
|
|
)}.xlsx`;
|
|
const filename = c.req.query("filename") || defaultFilename;
|
|
const age = c.req.query("age") || null;
|
|
const { data, error } = await tryCatch(lanesToExcel(age));
|
|
|
|
if (error) {
|
|
return c.json({
|
|
success: false,
|
|
message: "Error getting lane data.",
|
|
data: error,
|
|
});
|
|
}
|
|
|
|
return new Response(data, {
|
|
headers: {
|
|
"Content-Type":
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
"Content-Disposition": `attachment; filename="${filename}"`,
|
|
},
|
|
});
|
|
|
|
// return c.json({
|
|
// success: data.success,
|
|
// message: data.message,
|
|
// data: data.data,
|
|
// });
|
|
}
|
|
);
|
|
export default app;
|