refactor(old app): login migration to new app

This commit is contained in:
2025-10-21 20:22:21 -05:00
parent a2a8e0ef9f
commit eb3fa4dd52
28 changed files with 2273 additions and 2140 deletions

View File

@@ -1,10 +1,11 @@
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { ordersIn } from "../../controller/dm/ordersIn/ordersIn.js";
import { verify } from "hono/jwt";
import { forecastIn } from "../../controller/dm/forecast/forecastIn.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
import { forecastIn } from "../../controller/dm/forecast/forecastIn.js";
import { ordersIn } from "../../controller/dm/ordersIn/ordersIn.js";
const app = new OpenAPIHono();
@@ -16,61 +17,54 @@ const app = new OpenAPIHono();
// })
// .openapi("User");
app.openapi(
createRoute({
tags: ["logistics"],
summary: "Post forecast to DM",
method: "post",
path: "/postforecastin",
// request: {
// body: {
// content: {
// "application/json": { schema: Body },
// },
// },
// },
// description:
// "Provided a running number and lot number you can consume material.",
responses: responses(),
}),
async (c) => {
apiHit(c, { endpoint: "/postforecastin" });
const body = await c.req.parseBody();
const authHeader = c.req.header("Authorization");
const token = authHeader?.split("Bearer ")[1] || "";
//console.log(body); // File | string
createRoute({
tags: ["logistics"],
summary: "Post forecast to DM",
method: "post",
path: "/postforecastin",
middleware: authMiddleware,
// request: {
// body: {
// content: {
// "application/json": { schema: Body },
// },
// },
// },
// description:
// "Provided a running number and lot number you can consume material.",
responses: responses(),
}),
async (c) => {
apiHit(c, { endpoint: "/postforecastin" });
const body = await c.req.parseBody();
// if (body["fileType"] === "standard") {
// console.log(`doing standard orders in.`);
// }
const { data: payload, error: pe } = await tryCatch(
verify(token, process.env.JWT_SECRET!)
);
//console.log(body); // File | string
if (pe) {
return c.json({ success: false, message: "Unauthorized" }, 401);
}
// if (body["fileType"] === "standard") {
// console.log(`doing standard orders in.`);
// }
const { data: orders, error } = await tryCatch(
forecastIn(body, payload.user)
);
const { data: orders, error } = await tryCatch(
forecastIn(body, c.get("user")),
);
if (error) {
console.log(error);
return c.json(
{
success: false,
message: "Error posting forecast",
data: error,
},
400
);
}
if (error) {
console.log(error);
return c.json(
{
success: false,
message: "Error posting forecast",
data: error,
},
400,
);
}
return c.json({
success: orders?.success ?? false,
message: orders?.message ?? "Error posting forecast",
data: orders?.data ?? [],
});
}
return c.json({
success: orders?.success ?? false,
message: orders?.message ?? "Error posting forecast",
data: orders?.data ?? [],
});
},
);
export default app;