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

@@ -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` };
};