feat(eom): all endpoints created for the eom template to run in all plants
This commit is contained in:
@@ -3,8 +3,12 @@ import { db } from "../../../../database/dbclient.js";
|
||||
import { invHistoricalData } from "../../../../database/schema/historicalINV.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
import { format } from "date-fns";
|
||||
import { settings } from "../../../../database/schema/settings.js";
|
||||
|
||||
export const historicalInvByDate = async (date: string) => {
|
||||
export const historicalInvByDate = async (
|
||||
date: string,
|
||||
includePlantToken: boolean = false
|
||||
) => {
|
||||
const histDate = new Date(date);
|
||||
|
||||
const { data, error } = (await tryCatch(
|
||||
@@ -24,9 +28,28 @@ export const historicalInvByDate = async (date: string) => {
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `Historical inventory for ${date}`,
|
||||
data: data,
|
||||
};
|
||||
if (includePlantToken) {
|
||||
const { data: s, error: se } = (await tryCatch(
|
||||
db.select().from(settings).where(eq(settings.name, "plantToken"))
|
||||
)) as any;
|
||||
|
||||
if (se) {
|
||||
console.log("Error getting articles");
|
||||
return data;
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `Historical inventory for ${date}`,
|
||||
data: data.map((n: any) => {
|
||||
return { plantToken: s[0].value, ...n };
|
||||
}),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
message: `Historical inventory for ${date}`,
|
||||
data: data,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,8 +2,11 @@ import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
import { format } from "date-fns";
|
||||
import { query } from "../../sqlServer/prodSqlServer.js";
|
||||
import { lastPurchasePrice } from "../../sqlServer/querys/eom/lstPurchasePrice.js";
|
||||
import { db } from "../../../../database/dbclient.js";
|
||||
import { settings } from "../../../../database/schema/settings.js";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
export const lastPurchase = async () => {
|
||||
export const lastPurchase = async (includePlantToken: boolean = false) => {
|
||||
const { data, error } = (await tryCatch(
|
||||
query(lastPurchasePrice, "Last purchase price")
|
||||
)) as any;
|
||||
@@ -16,9 +19,28 @@ export const lastPurchase = async () => {
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `Last purchase price for all av in the last 5 years`,
|
||||
data: data.data,
|
||||
};
|
||||
if (includePlantToken) {
|
||||
const { data: s, error: se } = (await tryCatch(
|
||||
db.select().from(settings).where(eq(settings.name, "plantToken"))
|
||||
)) as any;
|
||||
|
||||
if (se) {
|
||||
console.log("Error getting articles");
|
||||
return data.data;
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `Last purchase price for all av in the last 5 years`,
|
||||
data: data.data.map((n: any) => {
|
||||
return { plantToken: s[0].value, ...n };
|
||||
}),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
message: `Last purchase price for all av in the last 5 years`,
|
||||
data: data.data,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
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 { lastSalesPriceCheck } from "../../sqlServer/querys/eom/lastSalesprice.js";
|
||||
import { format } from "date-fns-tz";
|
||||
|
||||
export const lastSales = async (date: string) => {
|
||||
export const lastSales = async (
|
||||
date: string,
|
||||
includePlantToken: boolean = false
|
||||
) => {
|
||||
const { data, error } = (await tryCatch(
|
||||
query(lastSalesPriceCheck.replace("[date]", date), "Last sales price")
|
||||
)) as any;
|
||||
@@ -15,9 +22,34 @@ export const lastSales = async (date: string) => {
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `Last sales price for all av in the last 5 years`,
|
||||
data: data.data,
|
||||
};
|
||||
if (includePlantToken) {
|
||||
const { data: s, error: se } = (await tryCatch(
|
||||
db.select().from(settings).where(eq(settings.name, "plantToken"))
|
||||
)) as any;
|
||||
|
||||
if (se) {
|
||||
console.log("Error getting articles");
|
||||
return data.data;
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `Historical inventory for ${date}`,
|
||||
data: data.data.map((n: any) => {
|
||||
return {
|
||||
plantToken: s[0].value,
|
||||
...n,
|
||||
validDate: format(n.validDate, "M/d/yyyy"),
|
||||
};
|
||||
}),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
message: `Last sales price for all av in the last 5 years`,
|
||||
data: data.data.map((n: any) => {
|
||||
return { ...n, validDate: format(n.validDate, "M/d/yyyy") };
|
||||
}),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
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 { lastSalesPriceCheck } from "../../sqlServer/querys/eom/lastSalesprice.js";
|
||||
import { consumptionCheck } from "../../sqlServer/querys/eom/consumptionCheck.js";
|
||||
import { format } from "date-fns-tz";
|
||||
|
||||
type Consumption = {
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
includePlantToken: boolean;
|
||||
};
|
||||
|
||||
export const getProductionConsumption = async (consumption: Consumption) => {
|
||||
const { data, error } = (await tryCatch(
|
||||
query(
|
||||
consumptionCheck
|
||||
.replace("[startDate]", consumption.startDate)
|
||||
.replace("[endDate]", consumption.endDate),
|
||||
"Last sales price"
|
||||
)
|
||||
)) as any;
|
||||
|
||||
if (error) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Error getting the last sales price",
|
||||
data: error,
|
||||
};
|
||||
}
|
||||
|
||||
if (consumption.includePlantToken) {
|
||||
const { data: s, error: se } = (await tryCatch(
|
||||
db.select().from(settings).where(eq(settings.name, "plantToken"))
|
||||
)) as any;
|
||||
|
||||
if (se) {
|
||||
console.log("Error getting articles");
|
||||
return data.data;
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `consumption data`,
|
||||
data: data.data.map((n: any) => {
|
||||
return {
|
||||
plantToken: s[0].value,
|
||||
...n,
|
||||
Prod_Date: format(n.Prod_Date, "M/d/yyyy"),
|
||||
};
|
||||
}),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
message: `consumption data`,
|
||||
data: data.data.map((n: any) => {
|
||||
return {
|
||||
...n,
|
||||
Prod_Date: format(n.Prod_Date, "M/d/yyyy"),
|
||||
};
|
||||
}),
|
||||
};
|
||||
}
|
||||
};
|
||||
66
lstV2/server/services/eom/controller/getPurchased.ts
Normal file
66
lstV2/server/services/eom/controller/getPurchased.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 { format } from "date-fns-tz";
|
||||
import { purchased } from "../../sqlServer/querys/eom/purchased.js";
|
||||
|
||||
type Consumption = {
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
includePlantToken: boolean;
|
||||
};
|
||||
|
||||
export const getPurchased = async (consumption: Consumption) => {
|
||||
const { data, error } = (await tryCatch(
|
||||
query(
|
||||
purchased
|
||||
.replace("[startDate]", consumption.startDate)
|
||||
.replace("[endDate]", consumption.endDate),
|
||||
"Last sales price"
|
||||
)
|
||||
)) as any;
|
||||
|
||||
if (error) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Error getting the last sales price",
|
||||
data: error,
|
||||
};
|
||||
}
|
||||
|
||||
if (consumption.includePlantToken) {
|
||||
const { data: s, error: se } = (await tryCatch(
|
||||
db.select().from(settings).where(eq(settings.name, "plantToken"))
|
||||
)) as any;
|
||||
|
||||
if (se) {
|
||||
console.log("Error getting articles");
|
||||
return data.data;
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `consumption data`,
|
||||
data: data.data.map((n: any) => {
|
||||
return {
|
||||
plantToken: s[0].value,
|
||||
...n,
|
||||
Received_Date: format(n.Received_Date, "M/d/yyyy"),
|
||||
};
|
||||
}),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
message: `consumption data`,
|
||||
data: data.data.map((n: any) => {
|
||||
return {
|
||||
...n,
|
||||
Received_Date: format(n.Received_Date, "M/d/yyyy"),
|
||||
};
|
||||
}),
|
||||
};
|
||||
}
|
||||
};
|
||||
68
lstV2/server/services/eom/controller/getSoldItems.ts
Normal file
68
lstV2/server/services/eom/controller/getSoldItems.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
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 { format } from "date-fns-tz";
|
||||
|
||||
import { soldOutItems } from "../../sqlServer/querys/eom/soldOut.js";
|
||||
|
||||
type Consumption = {
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
includePlantToken: boolean;
|
||||
};
|
||||
|
||||
export const getSoldItems = async (consumption: Consumption) => {
|
||||
const { data, error } = (await tryCatch(
|
||||
query(
|
||||
soldOutItems
|
||||
.replace("[startDate]", consumption.startDate)
|
||||
.replace("[endDate]", consumption.endDate),
|
||||
"Last sales price"
|
||||
)
|
||||
)) as any;
|
||||
|
||||
if (error) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Error getting the last sales price",
|
||||
data: error,
|
||||
};
|
||||
}
|
||||
|
||||
if (consumption.includePlantToken) {
|
||||
const { data: s, error: se } = (await tryCatch(
|
||||
db.select().from(settings).where(eq(settings.name, "plantToken"))
|
||||
)) as any;
|
||||
|
||||
if (se) {
|
||||
console.log("Error getting articles");
|
||||
return data.data;
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `consumption data`,
|
||||
data: data.data.map((n: any) => {
|
||||
return {
|
||||
plantToken: s[0].value,
|
||||
...n,
|
||||
DeliveryDate: format(n.DeliveryDate, "M/d/yyyy"),
|
||||
};
|
||||
}),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
message: `consumption data`,
|
||||
data: data.data.map((n: any) => {
|
||||
return {
|
||||
...n,
|
||||
DeliveryDate: format(n.DeliveryDate, "M/d/yyyy"),
|
||||
};
|
||||
}),
|
||||
};
|
||||
}
|
||||
};
|
||||
68
lstV2/server/services/eom/controller/getregrind.ts
Normal file
68
lstV2/server/services/eom/controller/getregrind.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
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 { lastSalesPriceCheck } from "../../sqlServer/querys/eom/lastSalesprice.js";
|
||||
import { consumptionCheck } from "../../sqlServer/querys/eom/consumptionCheck.js";
|
||||
import { format } from "date-fns-tz";
|
||||
import { regrindCheck } from "../../sqlServer/querys/eom/regrind.js";
|
||||
|
||||
type Consumption = {
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
includePlantToken: boolean;
|
||||
};
|
||||
|
||||
export const getRegrind = async (consumption: Consumption) => {
|
||||
const { data, error } = (await tryCatch(
|
||||
query(
|
||||
regrindCheck
|
||||
.replace("[startDate]", consumption.startDate)
|
||||
.replace("[endDate]", consumption.endDate),
|
||||
"Last sales price"
|
||||
)
|
||||
)) as any;
|
||||
|
||||
if (error) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Error getting the last sales price",
|
||||
data: error,
|
||||
};
|
||||
}
|
||||
|
||||
if (consumption.includePlantToken) {
|
||||
const { data: s, error: se } = (await tryCatch(
|
||||
db.select().from(settings).where(eq(settings.name, "plantToken"))
|
||||
)) as any;
|
||||
|
||||
if (se) {
|
||||
console.log("Error getting articles");
|
||||
return data.data;
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `consumption data`,
|
||||
data: data.data.map((n: any) => {
|
||||
return {
|
||||
plantToken: s[0].value,
|
||||
...n,
|
||||
Buchungsdatum: format(n.Buchungsdatum, "M/d/yyyy"),
|
||||
};
|
||||
}),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
message: `consumption data`,
|
||||
data: data.data.map((n: any) => {
|
||||
return {
|
||||
...n,
|
||||
Buchungsdatum: format(n.Buchungsdatum, "M/d/yyyy"),
|
||||
};
|
||||
}),
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -12,8 +12,23 @@ import { shiftChange } from "../sqlServer/querys/misc/shiftChange.js";
|
||||
import { createLog } from "../logger/logger.js";
|
||||
import lastPurch from "./route/getLastPurchPrice.js";
|
||||
import lastSales from "./route/getLastSalesPrice.js";
|
||||
import gpData from "./route/getGpData.js";
|
||||
import consumptionData from "./route/getProductionConsumption.js";
|
||||
import regrind from "./route/getregrind.js";
|
||||
import soldItems from "./route/getSoldItems.js";
|
||||
import purchased from "./route/getPurchased.js";
|
||||
|
||||
const routes = [stats, history, lastPurch, lastSales] as const;
|
||||
const routes = [
|
||||
stats,
|
||||
history,
|
||||
lastPurch,
|
||||
lastSales,
|
||||
gpData,
|
||||
consumptionData,
|
||||
regrind,
|
||||
soldItems,
|
||||
purchased,
|
||||
] as const;
|
||||
|
||||
const appRoutes = routes.forEach((route) => {
|
||||
app.route("/eom", route);
|
||||
|
||||
51
lstV2/server/services/eom/route/getGpData.ts
Normal file
51
lstV2/server/services/eom/route/getGpData.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||
|
||||
import { runGPQuery } from "../../sqlServer/gpSqlServer.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
const EomStat = z.object({
|
||||
plant: z.string().openapi({ example: "Salt Lake City" }),
|
||||
userRan: z.string().openapi({ example: "smith034" }),
|
||||
eomSheetVersion: z.string().openapi({ example: "0.0.223" }),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["eom"],
|
||||
summary: "Gets History Data by date.",
|
||||
method: "get",
|
||||
path: "/gpData",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
//const body = await c.req.json();
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
const q: any = c.req.queries();
|
||||
|
||||
apiHit(c, { endpoint: "/gpData" });
|
||||
try {
|
||||
const res = await runGPQuery({
|
||||
startDate: q["startDate"] ? q["startDate"][0] : "",
|
||||
endDate: q["endDate"] ? q["endDate"][0] : "",
|
||||
gpCode: q["gpCode"] ? q["gpCode"] : "",
|
||||
});
|
||||
|
||||
return c.json(
|
||||
{ success: res.success, message: res.message, data: res.data },
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "There was an error getting gp data.",
|
||||
data: error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
@@ -17,10 +17,12 @@ app.openapi(
|
||||
async (c) => {
|
||||
//const body = await c.req.json();
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
|
||||
const q: any = c.req.queries();
|
||||
apiHit(c, { endpoint: "/lastpurchprice" });
|
||||
try {
|
||||
const res = await lastPurchase();
|
||||
const res = await lastPurchase(
|
||||
q["includePlantToken"] ? true : false
|
||||
);
|
||||
|
||||
return c.json(
|
||||
{ success: res.success, message: res.message, data: res.data },
|
||||
|
||||
@@ -17,12 +17,14 @@ app.openapi(
|
||||
}),
|
||||
async (c) => {
|
||||
//const body = await c.req.json();
|
||||
const month: string = c.req.query("month") ?? "";
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
|
||||
const q: any = c.req.queries();
|
||||
apiHit(c, { endpoint: "/lastsalesprice" });
|
||||
try {
|
||||
const res = await lastSales(month);
|
||||
const res = await lastSales(
|
||||
q["month"] ? q["month"][0] : null,
|
||||
q["includePlantToken"] ? true : false
|
||||
);
|
||||
|
||||
return c.json(
|
||||
{ success: res.success, message: res.message, data: res.data },
|
||||
|
||||
52
lstV2/server/services/eom/route/getProductionConsumption.ts
Normal file
52
lstV2/server/services/eom/route/getProductionConsumption.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||
|
||||
import { runGPQuery } from "../../sqlServer/gpSqlServer.js";
|
||||
import { getProductionConsumption } from "../controller/getProductionConsumption.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
const EomStat = z.object({
|
||||
plant: z.string().openapi({ example: "Salt Lake City" }),
|
||||
userRan: z.string().openapi({ example: "smith034" }),
|
||||
eomSheetVersion: z.string().openapi({ example: "0.0.223" }),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["eom"],
|
||||
summary: "Gets History Data by date.",
|
||||
method: "get",
|
||||
path: "/productionconsumption",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
//const body = await c.req.json();
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
const q: any = c.req.queries();
|
||||
|
||||
apiHit(c, { endpoint: "/gpData" });
|
||||
try {
|
||||
const res = await getProductionConsumption({
|
||||
startDate: q["startDate"] ? q["startDate"][0] : "",
|
||||
endDate: q["endDate"] ? q["endDate"][0] : "",
|
||||
includePlantToken: q["includePlantToken"] ? true : false,
|
||||
});
|
||||
|
||||
return c.json(
|
||||
{ success: res.success, message: res.message, data: res.data },
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "There was an error getting gp data.",
|
||||
data: error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
50
lstV2/server/services/eom/route/getPurchased.ts
Normal file
50
lstV2/server/services/eom/route/getPurchased.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||
import { getPurchased } from "../controller/getPurchased.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
const EomStat = z.object({
|
||||
plant: z.string().openapi({ example: "Salt Lake City" }),
|
||||
userRan: z.string().openapi({ example: "smith034" }),
|
||||
eomSheetVersion: z.string().openapi({ example: "0.0.223" }),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["eom"],
|
||||
summary: "Gets History Data by date.",
|
||||
method: "get",
|
||||
path: "/purchased",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
//const body = await c.req.json();
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
const q: any = c.req.queries();
|
||||
|
||||
apiHit(c, { endpoint: "/regrind" });
|
||||
try {
|
||||
const res = await getPurchased({
|
||||
startDate: q["startDate"] ? q["startDate"][0] : "",
|
||||
endDate: q["endDate"] ? q["endDate"][0] : "",
|
||||
includePlantToken: q["includePlantToken"] ? true : false,
|
||||
});
|
||||
|
||||
return c.json(
|
||||
{ success: res.success, message: res.message, data: res.data },
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "There was an error getting gp data.",
|
||||
data: error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
54
lstV2/server/services/eom/route/getSoldItems.ts
Normal file
54
lstV2/server/services/eom/route/getSoldItems.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||
|
||||
import { runGPQuery } from "../../sqlServer/gpSqlServer.js";
|
||||
import { getProductionConsumption } from "../controller/getProductionConsumption.js";
|
||||
import { getRegrind } from "../controller/getregrind.js";
|
||||
import { getSoldItems } from "../controller/getSoldItems.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
const EomStat = z.object({
|
||||
plant: z.string().openapi({ example: "Salt Lake City" }),
|
||||
userRan: z.string().openapi({ example: "smith034" }),
|
||||
eomSheetVersion: z.string().openapi({ example: "0.0.223" }),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["eom"],
|
||||
summary: "Gets History Data by date.",
|
||||
method: "get",
|
||||
path: "/solditems",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
//const body = await c.req.json();
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
const q: any = c.req.queries();
|
||||
|
||||
apiHit(c, { endpoint: "/regrind" });
|
||||
try {
|
||||
const res = await getSoldItems({
|
||||
startDate: q["startDate"] ? q["startDate"][0] : "",
|
||||
endDate: q["endDate"] ? q["endDate"][0] : "",
|
||||
includePlantToken: q["includePlantToken"] ? true : false,
|
||||
});
|
||||
|
||||
return c.json(
|
||||
{ success: res.success, message: res.message, data: res.data },
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "There was an error getting gp data.",
|
||||
data: error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
53
lstV2/server/services/eom/route/getregrind.ts
Normal file
53
lstV2/server/services/eom/route/getregrind.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||
|
||||
import { runGPQuery } from "../../sqlServer/gpSqlServer.js";
|
||||
import { getProductionConsumption } from "../controller/getProductionConsumption.js";
|
||||
import { getRegrind } from "../controller/getregrind.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
const EomStat = z.object({
|
||||
plant: z.string().openapi({ example: "Salt Lake City" }),
|
||||
userRan: z.string().openapi({ example: "smith034" }),
|
||||
eomSheetVersion: z.string().openapi({ example: "0.0.223" }),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["eom"],
|
||||
summary: "Gets History Data by date.",
|
||||
method: "get",
|
||||
path: "/regrind",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
//const body = await c.req.json();
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
const q: any = c.req.queries();
|
||||
|
||||
apiHit(c, { endpoint: "/regrind" });
|
||||
try {
|
||||
const res = await getRegrind({
|
||||
startDate: q["startDate"] ? q["startDate"][0] : "",
|
||||
endDate: q["endDate"] ? q["endDate"][0] : "",
|
||||
includePlantToken: q["includePlantToken"] ? true : false,
|
||||
});
|
||||
|
||||
return c.json(
|
||||
{ success: res.success, message: res.message, data: res.data },
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "There was an error getting gp data.",
|
||||
data: error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
@@ -21,11 +21,14 @@ app.openapi(
|
||||
async (c) => {
|
||||
//const body = await c.req.json();
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
const month: string = c.req.query("month") ?? "";
|
||||
const q: any = c.req.queries();
|
||||
|
||||
apiHit(c, { endpoint: "/histinv" });
|
||||
try {
|
||||
const res = await historicalInvByDate(month);
|
||||
const res = await historicalInvByDate(
|
||||
q["month"] ? q["month"][0] : null,
|
||||
q["includePlantToken"] ? true : false
|
||||
);
|
||||
|
||||
return c.json(
|
||||
{ success: res.success, message: res.message, data: res.data },
|
||||
|
||||
Reference in New Issue
Block a user