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,9 +1,10 @@
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 { 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 { ordersIn } from "../../controller/dm/ordersIn/ordersIn.js";
const app = new OpenAPIHono();
@@ -15,61 +16,53 @@ const app = new OpenAPIHono();
// })
// .openapi("User");
app.openapi(
createRoute({
tags: ["logistics"],
summary: "Post orders to DM",
method: "post",
path: "/postbulkorders",
// 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: "/postbulkorders" });
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 orders to DM",
method: "post",
path: "/postbulkorders",
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: "/postbulkorders" });
const body = await c.req.parseBody();
//console.log(body); // File | string
// if (body["fileType"] === "standard") {
// console.log(`doing standard orders in.`);
// }
const { data: payload, error: pe } = await tryCatch(
verify(token, process.env.JWT_SECRET!)
);
// if (body["fileType"] === "standard") {
// console.log(`doing standard orders in.`);
// }
if (pe) {
return c.json({ success: false, message: "Unauthorized" }, 401);
}
const { data: orders, error } = await tryCatch(
ordersIn(body, c.get("user")),
);
const { data: orders, error } = await tryCatch(
ordersIn(body, payload.user)
);
if (error) {
console.log(error);
return c.json(
{
success: false,
message: "Error posting Orders",
data: error,
},
400,
);
}
if (error) {
console.log(error);
return c.json(
{
success: false,
message: "Error posting Orders",
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;

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;

View File

@@ -1,10 +1,10 @@
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { format } from "date-fns";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { standardTemplate } from "../../controller/dm/ordersIn/createTemplate.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { standardForCastTemplate } from "../../controller/dm/forecast/createTemplate.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { standardForCastTemplate } from "../../controller/dm/forecast/createTemplate.js";
const app = new OpenAPIHono();
@@ -16,52 +16,52 @@ const app = new OpenAPIHono();
// })
// .openapi("User");
app.openapi(
createRoute({
tags: ["logistics"],
summary: "Gets the standard Forecast Template",
method: "get",
path: "/bulkforcasttemplate",
// 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: "/bulkforcasttemplate" });
const defaultFilename = `bulkForcastTemplate-${format(
new Date(Date.now()),
"M-d-yyyy"
)}.xlsx`;
const filename = c.req.query("filename") || defaultFilename;
const { data, error } = await tryCatch(standardForCastTemplate());
createRoute({
tags: ["logistics"],
summary: "Gets the standard Forecast Template",
method: "get",
path: "/bulkforcasttemplate",
// 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: "/bulkforcasttemplate" });
const defaultFilename = `bulkForcastTemplate-${format(
new Date(Date.now()),
"M-d-yyyy",
)}.xlsx`;
const filename = c.req.query("filename") || defaultFilename;
const { data, error } = await tryCatch(standardForCastTemplate());
if (error) {
return c.json({
success: false,
message: "Error creating template",
data: error,
});
}
if (error) {
return c.json({
success: false,
message: "Error creating template",
data: error,
});
}
return new Response(data, {
headers: {
"Content-Type":
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"Content-Disposition": `attachment; filename="${filename}"`,
},
});
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,
// });
}
// return c.json({
// success: data.success,
// message: data.message,
// data: data.data,
// });
},
);
export default app;