refactor(invhist): reformated file
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
import { format } from "date-fns-tz";
|
||||
import { sql } from "drizzle-orm";
|
||||
import { db } from "../../../../database/dbclient.js";
|
||||
import { invHistoricalData } from "../../../../database/schema/historicalINV.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
import { createLog } from "../../logger/logger.js";
|
||||
import { query } from "../../sqlServer/prodSqlServer.js";
|
||||
import { totalInvNoRn } from "../../sqlServer/querys/dataMart/totalINV.js";
|
||||
import { format } from "date-fns-tz";
|
||||
import { serverSettings } from "../../server/controller/settings/getSettings.js";
|
||||
import { deleteHistory } from "./removeHistorical.js";
|
||||
import { query } from "../../sqlServer/prodSqlServer.js";
|
||||
import { activeArticle } from "../../sqlServer/querys/dataMart/article.js";
|
||||
import { totalInvNoRn } from "../../sqlServer/querys/dataMart/totalINV.js";
|
||||
import { deleteHistory } from "./removeHistorical.js";
|
||||
|
||||
export const historicalInvIMmport = async () => {
|
||||
const plantToken = serverSettings.filter((n) => n.name === "plantToken");
|
||||
const { data, error } = (await tryCatch(
|
||||
db.select().from(invHistoricalData)
|
||||
db.select().from(invHistoricalData),
|
||||
)) as any;
|
||||
|
||||
if (error) {
|
||||
@@ -21,7 +21,7 @@ export const historicalInvIMmport = async () => {
|
||||
"error",
|
||||
"eom",
|
||||
"eom",
|
||||
`There was an error getting the historical data`
|
||||
`There was an error getting the historical data`,
|
||||
);
|
||||
}
|
||||
// check if we have data already for today this way we dont duplicate anything.
|
||||
@@ -29,13 +29,13 @@ export const historicalInvIMmport = async () => {
|
||||
//today.setDate(today.getDate() - 1);
|
||||
|
||||
const dateCheck = data?.filter(
|
||||
(i: any) => i.histDate === format(today, "yyyy-MM-dd")
|
||||
(i: any) => i.histDate === format(today, "yyyy-MM-dd"),
|
||||
);
|
||||
|
||||
if (dateCheck.length === 0) {
|
||||
// get the historical data from the sql
|
||||
const { data: inv, error: invError } = (await tryCatch(
|
||||
query(totalInvNoRn, "eom historical data")
|
||||
query(totalInvNoRn.replace("(6, 1)", "(6)"), "eom historical data"),
|
||||
)) as any;
|
||||
|
||||
if (invError) {
|
||||
@@ -43,7 +43,7 @@ export const historicalInvIMmport = async () => {
|
||||
"error",
|
||||
"eom",
|
||||
"eom",
|
||||
`There was an error getting the sql data`
|
||||
`There was an error getting the sql data`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -54,7 +54,7 @@ export const historicalInvIMmport = async () => {
|
||||
}
|
||||
|
||||
const { data: articles, error: avError } = (await tryCatch(
|
||||
query(activeArticle, "Get active articles")
|
||||
query(activeArticle, "Get active articles"),
|
||||
)) as any;
|
||||
|
||||
const av = articles.data.length > 0 ? articles.data : ([] as any);
|
||||
@@ -68,11 +68,9 @@ export const historicalInvIMmport = async () => {
|
||||
article: i.av,
|
||||
articleDescription: i.Alias,
|
||||
materialType:
|
||||
av.filter((a: any) => a.IdArtikelvarianten === i.av)
|
||||
.length > 0
|
||||
? av.filter(
|
||||
(a: any) => a.IdArtikelvarianten === i.av
|
||||
)[0]?.TypeOfMaterial
|
||||
av.filter((a: any) => a.IdArtikelvarianten === i.av).length > 0
|
||||
? av.filter((a: any) => a.IdArtikelvarianten === i.av)[0]
|
||||
?.TypeOfMaterial
|
||||
: "Item not defined",
|
||||
total_QTY: i.Total_PalletQTY,
|
||||
avaliable_QTY: i.Avaliable_PalletQTY,
|
||||
@@ -84,7 +82,7 @@ export const historicalInvIMmport = async () => {
|
||||
});
|
||||
|
||||
const { data: dataImport, error: errorImport } = await tryCatch(
|
||||
db.insert(invHistoricalData).values(eomImportData)
|
||||
db.insert(invHistoricalData).values(eomImportData),
|
||||
);
|
||||
|
||||
if (errorImport) {
|
||||
@@ -92,18 +90,13 @@ export const historicalInvIMmport = async () => {
|
||||
"error",
|
||||
"eom",
|
||||
"eom",
|
||||
`There was an error importing all the inventory data.`
|
||||
`There was an error importing all the inventory data.`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dataImport) {
|
||||
createLog(
|
||||
"info",
|
||||
"eom",
|
||||
"eom",
|
||||
`All data was imported succefully.`
|
||||
);
|
||||
createLog("info", "eom", "eom", `All data was imported succefully.`);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user