fix(lots errors): fixes to prevent crashes when sql server not connected

This commit is contained in:
2025-04-17 18:40:35 -05:00
parent e7e35336f8
commit d5114ba243
5 changed files with 201 additions and 195 deletions

View File

@@ -11,18 +11,10 @@ export const getLots = async () => {
return {
success: false,
message: "There was an error getting the lots",
data: lotError,
data: [],
};
}
// if (!lotInfo.data.success) {
// return {
// success: false,
// message: "There was an error getting the lots",
// data: lotInfo.data.message,
// };
// }
return {
success: true,
message: "Current active lots that are technically released.",

View File

@@ -25,7 +25,7 @@ export const updatePrinters = async () => {
})
);
if (prodError) {
if (prodError || prodPrinters?.data.length > 10000) {
//console.log(prodError);
return {
success: false,
@@ -35,7 +35,7 @@ export const updatePrinters = async () => {
}
// do the printer update into our db
const prodPrinterInfo = prodPrinters.data;
const prodPrinterInfo = prodPrinters?.data;
for (let i = 0; i < prodPrinterInfo.length; i++) {
const printerStuff: any = {

View File

@@ -2,7 +2,6 @@
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { getPrinters } from "../../controller/printers/getPrinters.js";
import { getLots } from "../../controller/lots/lots.js";
const app = new OpenAPIHono({ strict: false });
@@ -15,7 +14,7 @@ app.openapi(
path: "/getlots",
responses: responses(),
}),
async (c) => {
async (c: any) => {
const { data: lotData, error: lotError } = await tryCatch(getLots());
if (lotError) {
@@ -26,9 +25,9 @@ app.openapi(
}
return c.json({
success: lotData.success,
message: lotData.message,
data: lotData.data,
success: lotData?.success,
message: lotData?.message,
data: lotData?.data,
});
}
);

View File

@@ -18,6 +18,20 @@ export const assignedPrinters = async () => {
data: lotError,
};
}
if (l.data.length === 0 && !l.data.sucess) {
createLog(
"error",
"lst",
"ocp",
`There was an error getting the lots: ${l?.message}`
);
return {
success: false,
message: "Error getting lots",
data: [],
};
}
const { data: print, error: printerError } = await tryCatch(getPrinters());
if (printerError) {
@@ -29,17 +43,11 @@ export const assignedPrinters = async () => {
}
const printers: any = print.data ?? [];
const lots: any = l.data.length === 0 ? [] : l.data;
const lots: any = l?.data.length === 0 ? null : l?.data;
if (!lots) {
createLog(
"error",
"lst",
"ocp",
`There was an error getting the lots: ${lots.message}`
);
return;
}
//console.log(lots);
return;
for (let i = 0; i < printers.length; i++) {
// is the printer assinged in alplalabel online?
const assigned = lots?.filter(