refactor(sql): improved the return function to show data [] when not connected, prevents crashes
This commit is contained in:
@@ -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: [],
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user