fix(datamart): added some fixed some
This commit is contained in:
29
server/services/dataMart/controller/getCustomerInventory.ts
Normal file
29
server/services/dataMart/controller/getCustomerInventory.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { query } from "../../sqlServer/prodSqlServer.js";
|
||||
import { customerInvNoHold } from "../../sqlServer/querys/dataMart/customerInventoryQuerys.js";
|
||||
|
||||
export const getCurrentCustomerInv = async (customer: any | null) => {
|
||||
let updatedQuery = customerInvNoHold;
|
||||
|
||||
if (customer) {
|
||||
//console.log(data.customer);
|
||||
updatedQuery = customerInvNoHold.replaceAll(
|
||||
"--and IdAdressen",
|
||||
`and IdAdressen = ${customer}`
|
||||
);
|
||||
}
|
||||
try {
|
||||
const inventory = await query(updatedQuery, "Get active inventory");
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "All customer inventory minus holds",
|
||||
data: inventory,
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
message: "There was an error getting the inventory",
|
||||
data: error,
|
||||
};
|
||||
}
|
||||
};
|
||||
66
server/services/dataMart/controller/getOpenOrders.ts
Normal file
66
server/services/dataMart/controller/getOpenOrders.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../../../../database/dbclient.js";
|
||||
import { settings } from "../../../../database/schema/settings.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
import { query } from "../../sqlServer/prodSqlServer.js";
|
||||
import { openOrders } from "../../sqlServer/querys/dataMart/openOrders.js";
|
||||
|
||||
export const getOpenOrders = async (data: any | null) => {
|
||||
const { data: plantToken, error: plantError } = await tryCatch(
|
||||
db.select().from(settings).where(eq(settings.name, "plantToken"))
|
||||
);
|
||||
if (plantError) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Error getting Settings",
|
||||
data: plantError,
|
||||
};
|
||||
}
|
||||
let orders = [];
|
||||
|
||||
let updatedQuery = openOrders;
|
||||
|
||||
// start days can be sent over
|
||||
if (data?.sDay) {
|
||||
updatedQuery = updatedQuery.replaceAll("[sDay]", data.sDay[0]);
|
||||
} else {
|
||||
updatedQuery = updatedQuery.replaceAll("[sDay]", "15");
|
||||
}
|
||||
|
||||
// end days can be sent over
|
||||
if (data?.eDay) {
|
||||
updatedQuery = updatedQuery.replaceAll("[eDay]", data.eDay[0]);
|
||||
} else {
|
||||
updatedQuery = updatedQuery.replaceAll("[eDay]", "5");
|
||||
}
|
||||
|
||||
try {
|
||||
orders = await query(updatedQuery, "Get active openorders");
|
||||
} catch (error) {
|
||||
return { success: false, message: "Current open orders", data: orders };
|
||||
}
|
||||
|
||||
// add plant token in
|
||||
const pOrders = orders.map((item: any) => {
|
||||
// const dateCon = new Date(item.loadingDate).toLocaleString("en-US", {
|
||||
// month: "numeric",
|
||||
// day: "numeric",
|
||||
// year: "numeric",
|
||||
// hour: "2-digit",
|
||||
// minute: "2-digit",
|
||||
// hour12: false,
|
||||
// });
|
||||
|
||||
//const dateCon = new Date(item.loadingDate).toISOString().replace("T", " ").split(".")[0];
|
||||
const dateCon = new Date(item.loadingDate).toISOString().split("T")[0];
|
||||
//const delDate = new Date(item.deliveryDate).toISOString().replace("T", " ").split(".")[0];
|
||||
const delDate = new Date(item.deliveryDate).toISOString().split("T")[0];
|
||||
return {
|
||||
plantToken: plantToken[0].value,
|
||||
...item,
|
||||
loadingDate: dateCon,
|
||||
deliveryDate: delDate,
|
||||
};
|
||||
});
|
||||
return { success: true, message: "Current open orders", data: pOrders };
|
||||
};
|
||||
@@ -1,14 +1,25 @@
|
||||
import { createLog } from "../../logger/logger.js";
|
||||
import { query } from "../../sqlServer/prodSqlServer.js";
|
||||
import {
|
||||
totalInvNoRn,
|
||||
totalInvRn,
|
||||
} from "../../sqlServer/querys/dataMart/totalINV.js";
|
||||
|
||||
export const getINV = async () => {
|
||||
export const getINV = async (rn: boolean) => {
|
||||
let inventory: any = [];
|
||||
|
||||
let updatedQuery = totalInvNoRn;
|
||||
|
||||
if (rn) {
|
||||
createLog(
|
||||
"info",
|
||||
"datamart",
|
||||
"datamart",
|
||||
"The user requested the running numbers this could take a while."
|
||||
);
|
||||
updatedQuery = totalInvRn;
|
||||
}
|
||||
|
||||
try {
|
||||
inventory = await query(updatedQuery, "Gets Curruent inv");
|
||||
return { success: true, message: "Current inv", data: inventory };
|
||||
|
||||
@@ -2,10 +2,20 @@ import { OpenAPIHono } from "@hono/zod-openapi";
|
||||
import activequerys from "./route/getCurrentQuerys.js";
|
||||
import getArticles from "./route/getActiveArticles.js";
|
||||
import currentInv from "./route/getInventory.js";
|
||||
import getCustomerInv from "./route/getCustomerInv.js";
|
||||
import getOpenOrders from "./route/getOpenOrders.js";
|
||||
import siloAdjustments from "./route/getSiloAdjustments.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const routes = [activequerys, getArticles, currentInv] as const;
|
||||
const routes = [
|
||||
activequerys,
|
||||
getArticles,
|
||||
currentInv,
|
||||
getCustomerInv,
|
||||
getOpenOrders,
|
||||
siloAdjustments,
|
||||
] as const;
|
||||
|
||||
const appRoutes = routes.forEach((route) => {
|
||||
app.route("/datamart", route);
|
||||
|
||||
@@ -23,25 +23,26 @@ const current: any = [
|
||||
// endpoint: "/api/v1/masterData/getMissingPKGData",
|
||||
// description: "Returns all packaging data that is missing either printer, layout, or carton layout",
|
||||
// },
|
||||
// {
|
||||
// name: "getCustomerInventory",
|
||||
// endpoint: "/api/v1/masterData/getCustomerInventory",
|
||||
// description: "Returns specific customer inventory based on there address ID.",
|
||||
// criteria: "customer",
|
||||
// },
|
||||
{
|
||||
name: "getCustomerInventory",
|
||||
endpoint: "/api/datamart/getcustomerinventory",
|
||||
description:
|
||||
"Returns specific customer inventory based on there address ID.",
|
||||
criteria: "customer",
|
||||
},
|
||||
// {
|
||||
// name: "getPalletLabels",
|
||||
// endpoint: "/api/v1/masterData/getPalletLabels",
|
||||
// description: "Returns specific amount of pallets RN, Needs label number and printer, Specfic to Dayton.",
|
||||
// criteria: "runningNumber,printerName,count",
|
||||
// },
|
||||
// {
|
||||
// name: "getOpenOrders",
|
||||
// endpoint: "/api/v1/masterData/getOpenOrders",
|
||||
// description:
|
||||
// "Returns open orders based on day count sent over, sDay 15 days in the past eDay 5 days in the future, can be left empty for this default days",
|
||||
// criteria: "sDay,eDay",
|
||||
// },
|
||||
{
|
||||
name: "getopenorders",
|
||||
endpoint: "/api/datamart/getopenorders",
|
||||
description:
|
||||
"Returns open orders based on day count sent over, sDay 15 days in the past eDay 5 days in the future, can be left empty for this default days",
|
||||
criteria: "sDay,eDay",
|
||||
},
|
||||
// {
|
||||
// name: "getOpenIncoming",
|
||||
// endpoint: "/api/v1/masterData/getOpenIncoming",
|
||||
@@ -60,7 +61,7 @@ const current: any = [
|
||||
// description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.",
|
||||
description:
|
||||
"Returns all inventory, excludes inv locations. no running numbers",
|
||||
//criteria: "includeRunnningNumbers", // uncomment this out once the improt process can be faster
|
||||
criteria: "includeRunnningNumbers", // uncomment this out once the improt process can be faster
|
||||
},
|
||||
// {
|
||||
// name: "getOpenOrderUpdates",
|
||||
@@ -69,13 +70,14 @@ const current: any = [
|
||||
// description: "Returns all orders based on customer id, leaving empty will pull everythinng in.",
|
||||
// criteria: "customer", // uncomment this out once the improt process can be faster
|
||||
// },
|
||||
// {
|
||||
// name: "getSiloAdjustment",
|
||||
// endpoint: "/api/v1/warehouse/getSiloAdjustment",
|
||||
// // description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.",
|
||||
// description: "Returns all siloadjustments in selected date range IE: 1/1/2025 to 1/31/2025",
|
||||
// criteria: "startDate,endDate", // uncomment this out once the improt process can be faster
|
||||
// },
|
||||
{
|
||||
name: "getSiloAdjustment",
|
||||
endpoint: "/api/v1/warehouse/getSiloAdjustment",
|
||||
// description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.",
|
||||
description:
|
||||
"Returns all siloadjustments in selected date range IE: 1/1/2025 to 1/31/2025",
|
||||
criteria: "startDate,endDate", // uncomment this out once the improt process can be faster
|
||||
},
|
||||
];
|
||||
|
||||
app.openapi(
|
||||
@@ -95,6 +97,7 @@ app.openapi(
|
||||
return c.json({
|
||||
success: true,
|
||||
message: "All Current Active Querys.",
|
||||
sheetVersion: 2.5,
|
||||
data: current,
|
||||
});
|
||||
}
|
||||
|
||||
53
server/services/dataMart/route/getCustomerInv.ts
Normal file
53
server/services/dataMart/route/getCustomerInv.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 { getCurrentCustomerInv } from "../controller/getCustomerInventory.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
const Body = z.object({
|
||||
includeRunnningNumbers: z.string().openapi({ example: "x" }),
|
||||
});
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["dataMart"],
|
||||
summary: "Returns All customer minus holds.",
|
||||
method: "get",
|
||||
path: "/getcustomerinventory",
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": { schema: Body },
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const customer: string = c.req.query("customer") ?? "";
|
||||
|
||||
// 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(
|
||||
getCurrentCustomerInv(customer ? customer : null)
|
||||
);
|
||||
|
||||
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;
|
||||
@@ -4,34 +4,33 @@ import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
import { getINV } from "../controller/getinventory.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
const Body = z.object({
|
||||
includeRunnningNumbers: z.string().openapi({ example: "x" }),
|
||||
});
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["dataMart"],
|
||||
summary: "Returns All current inventory.",
|
||||
method: "get",
|
||||
path: "/getinventory",
|
||||
// request: {
|
||||
// body: {
|
||||
// content: {
|
||||
// "application/json": { schema: Body },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": { schema: Body },
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
// const { data: body, error } = await c.req.json();
|
||||
const includeRunnningNumbers: string =
|
||||
c.req.query("includeRunnningNumbers") ?? "";
|
||||
|
||||
// if (error) {
|
||||
// return c.json({
|
||||
// success: false,
|
||||
// message: "Missing data please try again.",
|
||||
// });
|
||||
// }
|
||||
// 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(getINV());
|
||||
const { data, error } = await tryCatch(
|
||||
getINV(includeRunnningNumbers?.length > 0 ? true : false)
|
||||
);
|
||||
|
||||
if (error) {
|
||||
return c.json(
|
||||
|
||||
52
server/services/dataMart/route/getOpenOrders.ts
Normal file
52
server/services/dataMart/route/getOpenOrders.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
import { getOpenOrders } from "../controller/getOpenOrders.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
// const Body = z.object({
|
||||
// includeRunnningNumbers: z.string().openapi({ example: "x" }),
|
||||
// });
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["dataMart"],
|
||||
summary: "Returns All open orders.",
|
||||
method: "get",
|
||||
path: "/getopenorders",
|
||||
// request: {
|
||||
// body: {
|
||||
// content: {
|
||||
// "application/json": { schema: Body },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const customer: any = c.req.queries();
|
||||
|
||||
// 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(
|
||||
getOpenOrders(customer ? customer : null)
|
||||
);
|
||||
|
||||
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;
|
||||
69
server/services/dataMart/route/getSiloAdjustments.ts
Normal file
69
server/services/dataMart/route/getSiloAdjustments.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
import { getOpenOrders } from "../controller/getOpenOrders.js";
|
||||
import axios from "axios";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
// const Body = z.object({
|
||||
// includeRunnningNumbers: z.string().openapi({ example: "x" }),
|
||||
// });
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["dataMart"],
|
||||
summary: "Returns All open orders.",
|
||||
method: "get",
|
||||
path: "/getsilosdjustment",
|
||||
// request: {
|
||||
// body: {
|
||||
// content: {
|
||||
// "application/json": { schema: Body },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const customer: any = c.req.queries();
|
||||
|
||||
// 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(
|
||||
// getOpenOrders(customer ? customer : null)
|
||||
// );
|
||||
|
||||
// if (error) {
|
||||
// return c.json(
|
||||
// {
|
||||
// success: false,
|
||||
// message: "There was an error getting the inv.",
|
||||
// data: error,
|
||||
// },
|
||||
// 400
|
||||
// );
|
||||
// }
|
||||
|
||||
const dates: any = c.req.queries();
|
||||
|
||||
const { data, error } = await tryCatch(
|
||||
axios.get(
|
||||
`http://localhost:4400/api/v1/warehouse/getSilosAdjustment?startDate=${dates.startDate[0]}&endDate=${dates.endDate[0]}`
|
||||
)
|
||||
);
|
||||
|
||||
if (error) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "Error running query",
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
|
||||
return c.json({
|
||||
success: data?.data.success,
|
||||
message: data?.data.message,
|
||||
data: data?.data.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
Reference in New Issue
Block a user