feat(dm): standard forecast added in rest of migration to come
This commit is contained in:
49
backend/logistics/logistics.dm.postForecast.ts
Normal file
49
backend/logistics/logistics.dm.postForecast.ts
Normal 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,
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user