refactor(ocp): change the way logs are brought in and other changes to clean the code up
This commit is contained in:
@@ -60,11 +60,11 @@ export const labelingProcess = async ({
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`There is not a lot assigned to ${macId[0]?.Name}.`
|
||||
`There is not a lot assigned to ${line}.`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: `There is not a lot assigned to ${macId[0]?.Name}.`,
|
||||
message: `There is not a lot assigned to ${line}.`,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -128,7 +128,7 @@ export const labelingProcess = async ({
|
||||
}
|
||||
|
||||
// if there are more than 2 lots it might be an auto labeler, autolabeler will be defined by its id for now only dayton
|
||||
if (filteredLot.length > 2 && plantToken[0].value !== "usday1") {
|
||||
if (filteredLot?.length > 2 && plantToken[0].value !== "usday1") {
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
@@ -214,15 +214,15 @@ export const labelingProcess = async ({
|
||||
// create the label
|
||||
const label = await createLabel(filteredLot[0], userPrinted);
|
||||
|
||||
if (!label.success) {
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`There was an error creating the label: ${label.message}`
|
||||
);
|
||||
return { sucess: false, message: label.message, data: label.data };
|
||||
}
|
||||
// if (!label.success) {
|
||||
// createLog(
|
||||
// "error",
|
||||
// "labeling",
|
||||
// "ocp",
|
||||
// `There was an error creating the label: ${label.message}`
|
||||
// );
|
||||
// return { sucess: false, message: label.message, data: label.data };
|
||||
// }
|
||||
|
||||
// send over to be booked in if we can do it.
|
||||
const bookin = settingData.filter((s) => s.name === "bookin");
|
||||
|
||||
@@ -75,8 +75,16 @@ export const labelerTagRead = async (tagData: any) => {
|
||||
|
||||
// check if we need to manual check due to 20 pallets.
|
||||
if (currentPalletCheck <= cameraPalletCheck) {
|
||||
currentPalletCheck = currentPalletCheck + 1;
|
||||
currentPalletCheck++;
|
||||
labelingProcess({ line: numericString });
|
||||
createLog(
|
||||
"info",
|
||||
"dyco",
|
||||
"ocp",
|
||||
`You have printed ${currentPalletCheck} pallets, remaining until ${
|
||||
cameraPalletCheck - currentPalletCheck
|
||||
}.`
|
||||
);
|
||||
} else {
|
||||
currentPalletCheck = 0;
|
||||
createLog(
|
||||
|
||||
@@ -17,6 +17,9 @@ import { assignedPrinters } from "./utils/checkAssignments.js";
|
||||
import { printerCycle } from "./controller/printers/printerCycle.js";
|
||||
import stopPrinterCycle from "./routes/printers/stopCycle.js";
|
||||
import startPrinterCycle from "./routes/printers/startCycle.js";
|
||||
import { printerCycleAutoLabelers } from "./controller/printers/printerCycleAutoLabelers.js";
|
||||
import AutostartPrinterCycle from "./routes/printers/autoLabelerStart.js";
|
||||
import AutostopPrinterCycle from "./routes/printers/autoLabelerStop.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
@@ -27,6 +30,8 @@ const routes = [
|
||||
updateprinters,
|
||||
startPrinterCycle,
|
||||
stopPrinterCycle,
|
||||
AutostartPrinterCycle,
|
||||
AutostopPrinterCycle,
|
||||
// lots
|
||||
getLots,
|
||||
// labeling
|
||||
@@ -76,6 +81,7 @@ setTimeout(async () => {
|
||||
await updatePrinters();
|
||||
await assignedPrinters();
|
||||
printerCycle();
|
||||
printerCycleAutoLabelers();
|
||||
}
|
||||
}, 10 * 1000);
|
||||
|
||||
|
||||
41
server/services/ocp/routes/printers/autoLabelerStart.ts
Normal file
41
server/services/ocp/routes/printers/autoLabelerStart.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { printerCycle } from "../../controller/printers/printerCycle.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp:printers"],
|
||||
summary: "starts the printers cycling.",
|
||||
method: "get",
|
||||
path: "/startsprintercycle",
|
||||
middleware: authMiddleware,
|
||||
//description: "This might be a temp soltuin during the transtion between versions",
|
||||
// request: {
|
||||
// body: {content: {"application/json": {schema: CreateLog}}},
|
||||
// },
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const { data, error } = await tryCatch(printerCycle());
|
||||
const dataError: any = error;
|
||||
if (error) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "Error in stopping the printer cycle",
|
||||
data: dataError?.data,
|
||||
});
|
||||
}
|
||||
const getData: any = data;
|
||||
return c.json({
|
||||
success: getData?.success,
|
||||
message: getData?.message,
|
||||
data: getData.data ?? [],
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
41
server/services/ocp/routes/printers/autoLabelerStop.ts
Normal file
41
server/services/ocp/routes/printers/autoLabelerStop.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { stopPrinterCycle } from "../../controller/printers/printerCycle.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp:printers"],
|
||||
summary: "Stops the printers cycling.",
|
||||
method: "get",
|
||||
path: "/stopprintercycle",
|
||||
middleware: authMiddleware,
|
||||
//description: "This might be a temp soltuin during the transtion between versions",
|
||||
// request: {
|
||||
// body: {content: {"application/json": {schema: CreateLog}}},
|
||||
// },
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const { data, error } = await tryCatch(stopPrinterCycle());
|
||||
const dataError: any = error;
|
||||
if (error) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "Error in stopping the printer cycle",
|
||||
data: dataError?.data,
|
||||
});
|
||||
}
|
||||
const getData: any = data;
|
||||
return c.json({
|
||||
success: getData?.success,
|
||||
message: getData?.message,
|
||||
data: getData.data ?? [],
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
@@ -49,7 +49,7 @@ app.openapi(
|
||||
return c.json({
|
||||
success: getData?.success,
|
||||
message: getData?.message,
|
||||
data: getData.data ?? [],
|
||||
data: getData?.data ?? [],
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
@@ -28,8 +28,8 @@ export const assignedPrinters = async () => {
|
||||
};
|
||||
}
|
||||
|
||||
const printers: any = print.data;
|
||||
const lots: any = l.data;
|
||||
const printers: any = print.data ?? [];
|
||||
const lots: any = l.data ?? [];
|
||||
|
||||
for (let i = 0; i < printers.length; i++) {
|
||||
// is the printer assinged in alplalabel online?
|
||||
|
||||
Reference in New Issue
Block a user