feat(cards): migrated cards over

This commit is contained in:
2025-04-14 12:26:31 -05:00
parent 328b61f6cc
commit 087d14c585
21 changed files with 1318 additions and 334 deletions

View File

@@ -1,28 +1,41 @@
import { lanes } from "./cyclecountCheck.js";
export const getCycleCountCheck = async (
age: number = 1000,
type: string = ""
) => {
export const getCycleCountCheck = async (age: number = 1000, type: any) => {
/**
* Get the lane data based on the age and type
*/
let filteredLanes = lanes.filter((t: any) => t.DaysSinceLast >= age);
let filteredLanes = lanes;
if (type === "empty") {
let empty = lanes.filter((t: any) => t.rowType === type.toUpperCase());
if (type != "") {
return {
sucess: true,
message: `${filteredLanes.length} lanes that are of type ${type} and have not been cycle counted in the last ${age} days.`,
data: filteredLanes.filter(
(t: any) => t.rowType === type.toUpperCase()
message: `${empty.length} lanes that are of type ${type}.`,
data: empty.sort(
(a: any, b: any) => b.DaysSinceLast - a.DaysSinceLast
),
};
} else {
}
if (type != "") {
let noType = lanes.filter((t: any) => t.DaysSinceLast >= age);
return {
success: true,
message: `${filteredLanes.length} lanes grabed that have not been cycle counted in the last ${age} days.`,
data: filteredLanes,
sucess: true,
message: `${noType.length} lanes that are of type ${type} and have not been cycle counted in the last ${age} days.`,
data: noType
.filter((t: any) => t.rowType === type?.toUpperCase())
.sort((a: any, b: any) => b.DaysSinceLast - a.DaysSinceLast),
};
}
return {
success: true,
message: `${filteredLanes.length} lanes grabed that have not been cycle counted in the last ${age} days.`,
data: filteredLanes.sort(
(a: any, b: any) => b.DaysSinceLast - a.DaysSinceLast
),
};
};

View File

@@ -37,7 +37,7 @@ app.openapi(
return c.json({ success: false, message: "Missing Data." });
}
const check: any = body;
const check: any = body ?? { age: 90, type: null };
const { data: lanes, error: le } = await tryCatch(
getCycleCountCheck(check.age, check.type)
);

View File

@@ -0,0 +1,66 @@
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;