refactor(old app): login migration to new app
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,78 +1,74 @@
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { verify } from "hono/jwt";
|
||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||
import { createSiloAdjustment } from "../../controller/siloAdjustments/createSiloAdjustment.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 { createSiloAdjustment } from "../../controller/siloAdjustments/createSiloAdjustment.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const responseSchema = z.object({
|
||||
success: z.boolean().optional().openapi({ example: true }),
|
||||
message: z.string().optional().openapi({ example: "user access" }),
|
||||
success: z.boolean().optional().openapi({ example: true }),
|
||||
message: z.string().optional().openapi({ example: "user access" }),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["logistics"],
|
||||
summary: "Creates silo adjustmennt",
|
||||
method: "post",
|
||||
path: "/createsiloadjustment",
|
||||
middleware: authMiddleware,
|
||||
description:
|
||||
"Creates a silo adjustment for the silo if and stores the stock numbers.",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const { data, error } = await tryCatch(c.req.json());
|
||||
createRoute({
|
||||
tags: ["logistics"],
|
||||
summary: "Creates silo adjustmennt",
|
||||
method: "post",
|
||||
path: "/createsiloadjustment",
|
||||
middleware: authMiddleware,
|
||||
description:
|
||||
"Creates a silo adjustment for the silo if and stores the stock numbers.",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const { data, error } = await tryCatch(c.req.json());
|
||||
|
||||
if (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Missing data please try again",
|
||||
error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
apiHit(c, { endpoint: "/createsiloadjustment", lastBody: data });
|
||||
const authHeader = c.req.header("Authorization");
|
||||
const token = authHeader?.split("Bearer ")[1] || "";
|
||||
if (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Missing data please try again",
|
||||
error,
|
||||
},
|
||||
400,
|
||||
);
|
||||
}
|
||||
apiHit(c, { endpoint: "/createsiloadjustment", lastBody: data });
|
||||
|
||||
try {
|
||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||
try {
|
||||
//return apiReturn(c, true, access?.message, access?.data, 200);
|
||||
const createSiloAdj = await createSiloAdjustment(
|
||||
data,
|
||||
payload.user
|
||||
);
|
||||
const user = c.get("user");
|
||||
|
||||
return c.json(
|
||||
{
|
||||
success: createSiloAdj.success,
|
||||
message: createSiloAdj.message,
|
||||
data: createSiloAdj.data,
|
||||
},
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
//console.log(error);
|
||||
//return apiReturn(c, false, "Error in setting the user access", error, 400);
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Missing data please try again",
|
||||
error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
return c.json({ success: false, message: "Unauthorized" }, 401);
|
||||
}
|
||||
}
|
||||
try {
|
||||
try {
|
||||
//return apiReturn(c, true, access?.message, access?.data, 200);
|
||||
const createSiloAdj = await createSiloAdjustment(data, c.get("user"));
|
||||
|
||||
return c.json(
|
||||
{
|
||||
success: createSiloAdj.success,
|
||||
message: createSiloAdj.message,
|
||||
data: createSiloAdj.data,
|
||||
},
|
||||
200,
|
||||
);
|
||||
} catch (error) {
|
||||
//console.log(error);
|
||||
//return apiReturn(c, false, "Error in setting the user access", error, 400);
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Missing data please try again",
|
||||
error,
|
||||
},
|
||||
400,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
return c.json({ success: false, message: "Unauthorized" }, 401);
|
||||
}
|
||||
},
|
||||
);
|
||||
export default app;
|
||||
|
||||
@@ -1,88 +1,85 @@
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { verify } from "hono/jwt";
|
||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||
import { createSiloAdjustment } from "../../controller/siloAdjustments/createSiloAdjustment.js";
|
||||
import { postSiloComment } from "../../controller/siloAdjustments/postComment.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const ParamsSchema = z.object({
|
||||
adjId: z
|
||||
.string()
|
||||
.min(3)
|
||||
.openapi({
|
||||
param: {
|
||||
name: "adjId",
|
||||
in: "path",
|
||||
},
|
||||
example: "3b555052-a960-4301-8d38-a6f1acb98dbe",
|
||||
}),
|
||||
adjId: z
|
||||
.string()
|
||||
.min(3)
|
||||
.openapi({
|
||||
param: {
|
||||
name: "adjId",
|
||||
in: "path",
|
||||
},
|
||||
example: "3b555052-a960-4301-8d38-a6f1acb98dbe",
|
||||
}),
|
||||
});
|
||||
|
||||
const Body = z.object({
|
||||
comment: z
|
||||
.string()
|
||||
.openapi({ example: "Reason to why i had a badd adjustment." }),
|
||||
comment: z
|
||||
.string()
|
||||
.openapi({ example: "Reason to why i had a badd adjustment." }),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["logistics"],
|
||||
summary: "Post a comment to why you had a discrepancy",
|
||||
method: "post",
|
||||
path: "/postcomment/:adjId",
|
||||
middleware: authMiddleware,
|
||||
request: {
|
||||
params: ParamsSchema,
|
||||
body: { content: { "application/json": { schema: Body } } },
|
||||
},
|
||||
// description:
|
||||
// "Creates a silo adjustment for the silo if and stores the stock numbers.",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c: any) => {
|
||||
apiHit(c, { endpoint: "/postcomment" });
|
||||
const authHeader = c.req.header("Authorization");
|
||||
const token = authHeader?.split("Bearer ")[1] || "";
|
||||
const { adjId } = c.req.valid("param");
|
||||
createRoute({
|
||||
tags: ["logistics"],
|
||||
summary: "Post a comment to why you had a discrepancy",
|
||||
method: "post",
|
||||
path: "/postcomment/:adjId",
|
||||
middleware: authMiddleware,
|
||||
request: {
|
||||
params: ParamsSchema,
|
||||
body: { content: { "application/json": { schema: Body } } },
|
||||
},
|
||||
// description:
|
||||
// "Creates a silo adjustment for the silo if and stores the stock numbers.",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c: any) => {
|
||||
apiHit(c, { endpoint: "/postcomment" });
|
||||
const { adjId } = c.req.valid("param");
|
||||
|
||||
try {
|
||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||
try {
|
||||
//return apiReturn(c, true, access?.message, access?.data, 200);
|
||||
const data = await c.req.json();
|
||||
try {
|
||||
try {
|
||||
//return apiReturn(c, true, access?.message, access?.data, 200);
|
||||
const data = await c.req.json();
|
||||
|
||||
const addComment = await postSiloComment(
|
||||
adjId,
|
||||
data.comment,
|
||||
data.key,
|
||||
payload.user
|
||||
);
|
||||
const addComment = await postSiloComment(
|
||||
adjId,
|
||||
data.comment,
|
||||
data.key,
|
||||
c.get("user"),
|
||||
);
|
||||
|
||||
console.log(addComment);
|
||||
return c.json(
|
||||
{
|
||||
success: addComment.success,
|
||||
message: addComment.message,
|
||||
data: addComment.data,
|
||||
},
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Missing data please try again",
|
||||
error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
return c.json({ success: false, message: "Unauthorized" }, 401);
|
||||
}
|
||||
}
|
||||
console.log(addComment);
|
||||
return c.json(
|
||||
{
|
||||
success: addComment.success,
|
||||
message: addComment.message,
|
||||
data: addComment.data,
|
||||
},
|
||||
200,
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Missing data please try again",
|
||||
error,
|
||||
},
|
||||
400,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
return c.json({ success: false, message: "Unauthorized" }, 401);
|
||||
}
|
||||
},
|
||||
);
|
||||
export default app;
|
||||
|
||||
Reference in New Issue
Block a user