refactor(sql): improved the return function to show data [] when not connected, prevents crashes

This commit is contained in:
2025-04-24 21:24:39 -05:00
parent 3573fd1a5b
commit ead63d4b41
36 changed files with 323 additions and 141 deletions

View File

@@ -7,15 +7,21 @@ import { ocmeCycleCounts } from "../../../../database/schema/ocmeCycleCounts.js"
import { db } from "../../../../database/dbclient.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { createLog } from "../../logger/logger.js";
import { prodEndpointCreation } from "../../../globalUtils/createUrl.js";
export const prepareLane =
"https://usday1prod.alpla.net/application/public/v1.1/Warehousing/PrepareLaneForInventory";
export const openLane =
"https://usday1prod.alpla.net/application/public/v1.0/Warehousing/InventoryOpen";
export const closeLane =
"https://usday1prod.alpla.net/application/public/v1.0/Warehousing/InventoryClose";
export const releaseLane =
"https://usday1prod.alpla.net/application/public/v1.1/Warehousing/ReleaseLaneFromInventory";
export const prepareLane = await prodEndpointCreation(
"/public/v1.1/Warehousing/PrepareLaneForInventory"
);
export const openLane = await prodEndpointCreation(
"/public/v1.0/Warehousing/InventoryOpen"
);
export const closeLane = await prodEndpointCreation(
"/public/v1.0/Warehousing/InventoryClose"
);
export const releaseLane = await prodEndpointCreation(
"/public/v1.1/Warehousing/ReleaseLaneFromInventory"
);
export const scannerID = 500;
export const cycleCount = async (lane: any, user: User) => {
/**
@@ -27,7 +33,7 @@ export const cycleCount = async (lane: any, user: User) => {
const ocme = await ocmeInv(lane);
// get alpla stock data
const alplaStock = await alplaStockInv(ocme[0].alpla_laneID);
const alplaStock: any = await alplaStockInv(ocme[0].alpla_laneID);
// create a new array that has the merge happen.
const mergeOcmeData = ocme.map((d: any) => {

View File

@@ -1,5 +1,5 @@
import {query} from "../../../sqlServer/prodSqlServer.js";
import {alplaStock} from "../../../sqlServer/querys/ocme/alplaStockInvByID.js";
import { query } from "../../../sqlServer/prodSqlServer.js";
import { alplaStock } from "../../../sqlServer/querys/ocme/alplaStockInvByID.js";
export const alplaStockInv = async (laneID: string) => {
/**
@@ -9,8 +9,8 @@ export const alplaStockInv = async (laneID: string) => {
const stock = alplaStock.replaceAll("[laneID]", `${laneID}`);
try {
const stockData = await query(stock, "Stock Data");
return stockData;
const stockData: any = await query(stock, "Stock Data");
return stockData.data;
} catch (error) {
console.log(error);
return [];

View File

@@ -1,13 +1,18 @@
// full lane count
import axios from "axios";
import {delay} from "../../../../globalUtils/delay.js";
import {createLog} from "../../../logger/logger.js";
import {openLane, prepareLane, scannerID} from "../cycleCount.js";
import type {User} from "../../../../types/users.js";
import { delay } from "../../../../globalUtils/delay.js";
import { createLog } from "../../../logger/logger.js";
import { openLane, prepareLane, scannerID } from "../cycleCount.js";
import type { User } from "../../../../types/users.js";
import { prodEndpointCreation } from "../../../../globalUtils/createUrl.js";
let delayTime = 100;
export const fullLaneCount = async (user: User, lane: string, ocmeLanes: any) => {
export const fullLaneCount = async (
user: User,
lane: string,
ocmeLanes: any
) => {
// prepare the lane.
try {
const openlane = await axios({
@@ -59,7 +64,9 @@ export const fullLaneCount = async (user: User, lane: string, ocmeLanes: any) =>
try {
const openLane = await axios({
method: "POST",
url: "https://usday1prod.alpla.net/application/public/v1.0/Warehousing/InventoryCount",
url: await prodEndpointCreation(
"/public/v1.0/Warehousing/InventoryCount"
),
headers: {
Authorization: `Basic ${user.prod}`,
"Content-Type": "application/json",
@@ -84,7 +91,9 @@ export const fullLaneCount = async (user: User, lane: string, ocmeLanes: any) =>
try {
const openLane = await axios({
method: "POST",
url: "https://usday1prod.alpla.net/application/public/v1.0/Warehousing/InventoryClose",
url: await prodEndpointCreation(
"/public/v1.0/Warehousing/InventoryClose"
),
headers: {
Authorization: `Basic ${user.prod}`,
"Content-Type": "application/json",
@@ -103,7 +112,9 @@ export const fullLaneCount = async (user: User, lane: string, ocmeLanes: any) =>
try {
const openLane = await axios({
method: "POST",
url: "https://usday1prod.alpla.net/application/public/v1.1/Warehousing/ReleaseLaneFromInventory",
url: await prodEndpointCreation(
"/public/v1.1/Warehousing/ReleaseLaneFromInventory"
),
headers: {
Authorization: `Basic ${user.prod}`,
"Content-Type": "application/json",
@@ -113,7 +124,12 @@ export const fullLaneCount = async (user: User, lane: string, ocmeLanes: any) =>
},
});
createLog("info", user.username!, "ocme-count", openLane.data.message);
createLog(
"info",
user.username!,
"ocme-count",
openLane.data.message
);
} catch (error) {
createLog("error", user.username!, "ocme-count", `${error}`);
}
@@ -122,5 +138,5 @@ export const fullLaneCount = async (user: User, lane: string, ocmeLanes: any) =>
createLog("error", user.username!, "ocme-count", `${error}`);
}
return {success: true, message: `Lane completed`};
return { success: true, message: `Lane completed` };
};

View File

@@ -1,11 +1,11 @@
import axios from "axios";
import {createLog} from "../../logger/logger.js";
import {shipmentPallets} from "../../sqlServer/querys/ocme/shipmentPallets.js";
import {getShipmentData} from "./getShipmentData.js";
import {query} from "../../sqlServer/prodSqlServer.js";
import {db} from "../../../../database/dbclient.js";
import {settings} from "../../../../database/schema/settings.js";
import {lotRestriction} from "./lotrestriction.js";
import { createLog } from "../../logger/logger.js";
import { shipmentPallets } from "../../sqlServer/querys/ocme/shipmentPallets.js";
import { getShipmentData } from "./getShipmentData.js";
import { query } from "../../sqlServer/prodSqlServer.js";
import { db } from "../../../../database/dbclient.js";
import { settings } from "../../../../database/schema/settings.js";
import { lotRestriction } from "./lotrestriction.js";
export const getShipmentPallets = async (shipmentID: any) => {
let ocmeLanes: any = [];
@@ -23,43 +23,65 @@ export const getShipmentPallets = async (shipmentID: any) => {
const shipments = await getShipmentData();
// filter the shipment so we can get the correct data from it.
const filteredShipment = shipments.data.filter((order: any) => order.LoadingOrderId === parseInt(shipmentID));
const filteredShipment = shipments.data.filter(
(order: any) => order.LoadingOrderId === parseInt(shipmentID)
);
// getting the criteria we want to look at.
let tmpCheck: any = [];
if (filteredShipment.length === 0) {
createLog("error", "ocme", "ocme", "Invalid shipment id was provided and cant do anything else.");
createLog(
"error",
"ocme",
"ocme",
"Invalid shipment id was provided and cant do anything else."
);
return {
success: false,
message: "Invalid shipmentID sent over please try again",
};
} else {
tmpCheck = filteredShipment[0].Remark.split(",")
.map((item: any) => item.trim()) // removes accedental spaces if there are any
.map((i: any) => i.toLowerCase());
.map((item: any) => item.trim()) // removes accedental spaces if there are any
.map((i: any) => i.toLowerCase());
}
// removing the agv out of the array
let checks = tmpCheck.filter((i: any) => i !== "agv");
let shipmentQ = shipmentPallets
.replaceAll("[article]", filteredShipment[0].LoadingPlan[0].ArticleVariantId)
.replaceAll("[fifo]", setting.filter((n) => n.name === "fifoCheck")[0].value);
.replaceAll(
"[article]",
filteredShipment[0].LoadingPlan[0].ArticleVariantId
)
.replaceAll(
"[fifo]",
setting.filter((n) => n.name === "fifoCheck")[0].value
);
const addressCheck = setting.filter((n) => n.name === "monitorAddress");
if (parseInt(addressCheck[0].value) === filteredShipment[0].LoadingPlan[0].AddressId) {
if (
parseInt(addressCheck[0].value) ===
filteredShipment[0].LoadingPlan[0].AddressId
) {
// if there really ends up being more than 5000 pallets then well we need to fix this later, also an insane issue to have this many that would need to be monitored
shipmentQ = shipmentQ.replaceAll("[totalPallets]", "5000");
} else {
shipmentQ = shipmentQ.replaceAll("[totalPallets]", filteredShipment[0].LoadingPlan[0].PackagingQuantity);
shipmentQ = shipmentQ.replaceAll(
"[totalPallets]",
filteredShipment[0].LoadingPlan[0].PackagingQuantity
);
}
// temp situation only getting the lanes we want to look in
// Convert laneArray to a comma-separated string with each value quoted
let noBlock;
if (checks.includes("all")) {
noBlock = shipmentQ.replaceAll("and GesperrtAktivSum in (0) ", "--and GesperrtAktivSum in (0) ");
noBlock = shipmentQ.replaceAll(
"and GesperrtAktivSum in (0) ",
"--and GesperrtAktivSum in (0) "
);
} else {
noBlock = shipmentQ;
}
@@ -78,13 +100,19 @@ export const getShipmentPallets = async (shipmentID: any) => {
let shipmentLane = shipmentQ.replaceAll("[lanes]", laneString);
let shipmentPals = [];
let shipmentPals: any = [];
//console.log(shipmentLane);
try {
shipmentPals = await query(shipmentLane, "Get shipmentPals");
const res: any = await query(shipmentLane, "Get shipmentPals");
shipmentPals = res.data;
} catch (err) {
createLog("error", "ocme", "ocme", `Error from running the shippment pallets query: ${err}`);
return {success: false, message: err, data: []};
createLog(
"error",
"ocme",
"ocme",
`Error from running the shippment pallets query: ${err}`
);
return { success: false, message: err, data: [] };
}
let filteredPallets = shipmentPals;
@@ -94,7 +122,10 @@ export const getShipmentPallets = async (shipmentID: any) => {
return {
success: true,
message: `There are a total of ${filteredPallets.length} pallet(s) that are in this shipment.`,
data: filteredPallets.splice(0, filteredShipment[0].LoadingPlan[0].PackagingQuantity),
data: filteredPallets.splice(
0,
filteredShipment[0].LoadingPlan[0].PackagingQuantity
),
};
}
@@ -112,21 +143,35 @@ export const getShipmentPallets = async (shipmentID: any) => {
return {
success: true,
message: `There are a total of ${filteredPallets.length} pallet(s) that are in this shipment.`,
data: filteredPallets.splice(0, filteredShipment[0].LoadingPlan[0].PackagingQuantity),
data: filteredPallets.splice(
0,
filteredShipment[0].LoadingPlan[0].PackagingQuantity
),
};
}
// for "what ever case" follow the logic. to check addresses and resitrions
if (parseInt(addressCheck[0].value) === filteredShipment[0].LoadingPlan[0].AddressId) {
if (
parseInt(addressCheck[0].value) ===
filteredShipment[0].LoadingPlan[0].AddressId
) {
createLog(
"info",
"ocme",
"ocme",
"This shipment has restrictions on it and will go throught the lots filtering process"
);
filteredPallets = await lotRestriction(shipmentPals, filteredShipment[0].LoadingPlan[0].PackagingQuantity);
filteredPallets = await lotRestriction(
shipmentPals,
filteredShipment[0].LoadingPlan[0].PackagingQuantity
);
} else {
createLog("info", "ocme", "ocme", "This shipment is cleared to send what ever.");
createLog(
"info",
"ocme",
"ocme",
"This shipment is cleared to send what ever."
);
}
return {

View File

@@ -25,10 +25,11 @@ export const postLabelData = async (data: any) => {
data: [],
};
}
let label;
let label: any = [];
const filterQuery = labelData.replaceAll("[rn]", newData.runningNr);
try {
label = await query(filterQuery, "Label data");
const res: any = await query(filterQuery, "Label data");
label = res.data;
} catch (error) {
createLog(
"error",