50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
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,
|
|
});
|
|
}
|
|
};
|