feat(fakeedi): fake edi macro update implemented
This commit is contained in:
39
server/services/dataMart/controller/fakeEDIUpdate.ts
Normal file
39
server/services/dataMart/controller/fakeEDIUpdate.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { createLog } from "../../logger/logger.js";
|
||||
import { query } from "../../sqlServer/prodSqlServer.js";
|
||||
import { fakeEDIUpdate } from "../../sqlServer/querys/dataMart/fakeEDIUpdate.js";
|
||||
|
||||
export const getFakeEDI = async (address: string) => {
|
||||
let fakeEDI: any = [];
|
||||
|
||||
let updatedQuery = fakeEDIUpdate;
|
||||
|
||||
if (address) {
|
||||
createLog(
|
||||
"info",
|
||||
"datamart",
|
||||
"datamart",
|
||||
"The user requested a specific address."
|
||||
);
|
||||
updatedQuery = fakeEDIUpdate.replace(
|
||||
"--and IdAdresse = 14",
|
||||
`and IdAdresse = ${address}`
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
fakeEDI = await query(updatedQuery, "Gets fakeEDI orders to be fixed");
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Current open orders",
|
||||
data: fakeEDI.data,
|
||||
};
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return {
|
||||
success: false,
|
||||
message: "There was an error open orders",
|
||||
data: error,
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -5,6 +5,7 @@ import currentInv from "./route/getInventory.js";
|
||||
import getCustomerInv from "./route/getCustomerInv.js";
|
||||
import getOpenOrders from "./route/getOpenOrders.js";
|
||||
import getDeliveryByDate from "./route/getDeliveryDateByRange.js";
|
||||
import fakeEDI from "./route/fakeEDI.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
@@ -15,6 +16,7 @@ const routes = [
|
||||
getCustomerInv,
|
||||
getOpenOrders,
|
||||
getDeliveryByDate,
|
||||
fakeEDI,
|
||||
] as const;
|
||||
|
||||
const appRoutes = routes.forEach((route) => {
|
||||
|
||||
53
server/services/dataMart/route/fakeEDI.ts
Normal file
53
server/services/dataMart/route/fakeEDI.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
import { getINV } from "../controller/getinventory.js";
|
||||
import { getFakeEDI } from "../controller/fakeEDIUpdate.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
const Body = z.object({
|
||||
address: z.string().openapi({ example: "x" }),
|
||||
});
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["dataMart"],
|
||||
summary: "Returns all open orders that need to be updated in fake edi.",
|
||||
method: "get",
|
||||
path: "/fakeediupdate",
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": { schema: Body },
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const address: string = c.req.query("address") ?? "";
|
||||
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
//apiHit(c, { endpoint: `api/logger/logs/id` });
|
||||
const { data, error } = await tryCatch(
|
||||
getFakeEDI(address.toString() ?? "")
|
||||
);
|
||||
|
||||
if (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "There was an error getting the inv.",
|
||||
data: error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
return c.json({
|
||||
success: data.success,
|
||||
message: data.message,
|
||||
data: data.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
Reference in New Issue
Block a user