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

@@ -2,12 +2,20 @@ import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { query } from "../../../sqlServer/prodSqlServer.js";
import { lotQuery } from "../../../sqlServer/querys/ocp/lots.js";
type LotInfo = {
success: boolean;
message: string;
data: any[];
};
export const getLots = async () => {
const { data: lotInfo, error: lotError } = await tryCatch(
const { data: l, error: lotError } = await tryCatch(
query(lotQuery, "Alplalabel online lots")
);
const lotInfo = l as LotInfo;
if (lotError) {
console.log("lot error", lotError);
return {
success: false,
message: "There was an error getting the lots",
@@ -15,9 +23,17 @@ export const getLots = async () => {
};
}
return {
success: true,
message: "Current active lots that are technically released.",
data: lotInfo,
};
if (lotInfo.success) {
return {
success: true,
message: "Current active lots that are technically released.",
data: lotInfo,
};
} else {
return {
success: true,
message: `Error getting lot info due to: ${lotInfo.message}.`,
data: [],
};
}
};

View File

@@ -42,7 +42,8 @@ export const prolinkCheck = async (lot: any) => {
// run the query
try {
const prolink = await query(prolinkQuery, "Prolink Checks");
const p: any = await query(prolinkQuery, "Prolink Checks");
const prolink = p.data;
// filter out the lot
const filterdLot = prolink.filter(
(p: any) => p.AlplaLabelOnline === lot