refactor(dm): mapped remainder of the forecast. will need to run backup test
Some checks failed
Build and Push LST Docker Image / docker (push) Failing after 40s
Some checks failed
Build and Push LST Docker Image / docker (push) Failing after 40s
the test server wouldnt do the backup so waiting on this one
This commit is contained in:
65
backend/logistics/logistics.dm.postData.ts
Normal file
65
backend/logistics/logistics.dm.postData.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
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";
|
||||
|
||||
type PostData = {
|
||||
receivingPlantId: string;
|
||||
documentName: string;
|
||||
sender: string;
|
||||
customerId: string;
|
||||
positions: unknown[];
|
||||
};
|
||||
type Data = {
|
||||
type: "orders" | "forecast";
|
||||
endpoint: string;
|
||||
data: PostData;
|
||||
};
|
||||
export const postData = async (data: Data, user: any) => {
|
||||
const posting = await runProdApi(
|
||||
{
|
||||
method: "post",
|
||||
endpoint: data.endpoint,
|
||||
data: [data.data],
|
||||
},
|
||||
"Forecast post",
|
||||
);
|
||||
|
||||
if (!posting?.success) {
|
||||
return returnFunc({
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "dm",
|
||||
subModule: data.type === "orders" ? "orders" : "forecast",
|
||||
message:
|
||||
posting?.message ??
|
||||
`Error in posting the ${data.type === "orders" ? "orders" : "forecast"} data`,
|
||||
data: posting?.data ?? [],
|
||||
notify: false,
|
||||
});
|
||||
}
|
||||
|
||||
if (posting.success) {
|
||||
if (data.type === "forecast") {
|
||||
await db.insert(forecastImport).values({
|
||||
receivingPlantId: data.data.receivingPlantId ?? "test1",
|
||||
documentName: data.data.documentName ?? "forecast-data-missing",
|
||||
sender: data.data.sender ?? "lst-user",
|
||||
customerId: data.data.customerId ?? "0",
|
||||
rawData: data ?? [],
|
||||
add_user: user.username ?? undefined,
|
||||
upd_user: user.username ?? undefined,
|
||||
});
|
||||
}
|
||||
|
||||
return returnFunc({
|
||||
success: true,
|
||||
level: "info",
|
||||
module: "dm",
|
||||
subModule: data.type === "orders" ? "orders" : "forecast",
|
||||
message: posting?.message ?? "",
|
||||
data: (data.data as any) ?? [],
|
||||
notify: false,
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user