feat(dm): standard forecast added in rest of migration to come

This commit is contained in:
2026-06-14 03:52:34 -05:00
parent d85f08cb19
commit 39db142db4
18 changed files with 6163 additions and 4 deletions

View File

@@ -0,0 +1,49 @@
import { db } from "../db/db.controller.js";
import { forecastImport } from "../db/schema/forecastImports.schema.js";
import { runProdApi } from "../utils/prodEndpoint.utils.js";
import { returnFunc } from "../utils/returnHelper.utils.js";
export const postForecast = async (data: any, user: any) => {
const forecast = await runProdApi(
{
method: "post",
endpoint: "/public/v1.0/DemandManagement/DELFOR",
data: [data],
},
"Forecast post",
);
if (!forecast?.success) {
return returnFunc({
success: false,
level: "error",
module: "dm",
subModule: "forecast",
message: forecast?.message ?? "Error in posting the forecast data",
data: forecast?.data ?? [],
notify: false,
});
}
if (forecast.success) {
await db.insert(forecastImport).values({
receivingPlantId: data.receivingPlantId ?? "test1",
documentName: data.documentName ?? "forecast-data-missing",
sender: data.sender ?? "lst-user",
customerId: data.customerId ?? "0",
rawData: data ?? [],
add_user: user.username ?? undefined,
upd_user: user.username ?? undefined,
});
return returnFunc({
success: true,
level: "info",
module: "dm",
subModule: "forecast",
message: forecast?.message ?? "",
data: data ?? [],
notify: false,
});
}
};