feat(eom): all endpoints created for the eom template to run in all plants

This commit is contained in:
2025-09-30 19:55:35 -05:00
parent a7f45abfeb
commit 9a14f250b6
25 changed files with 872 additions and 33 deletions

View File

@@ -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,
};
}
};