feat(labeling): ratios reset for labeling implemeneted

This commit is contained in:
2025-07-14 12:37:38 -05:00
parent a7f8e39bac
commit 61f0b7f06b
11 changed files with 340 additions and 8 deletions

View File

@@ -1,23 +1,23 @@
import { eq } from "drizzle-orm";
import { db } from "../../../../../database/dbclient.js";
import { labelRatio } from "../../../../../database/schema/ratios.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
export const getLabelRatio = async () => {
const { data: labelInfo, error: labelError } = await tryCatch(
db.select().from(labelRatio)
db.select().from(labelRatio).where(eq(labelRatio.name, "label"))
);
if (labelError) {
return {
success: false,
message: "There was an error getting the labels",
message: "There was an error getting the labelratio",
data: [labelError],
};
}
return {
success: true,
message: "Current labels order by upd_Date.",
count: labelInfo.length,
message: "Current labelratio.",
data: labelInfo,
};
};

View File

@@ -1,4 +1,4 @@
import { sql } from "drizzle-orm";
import { eq, sql } from "drizzle-orm";
import { db } from "../../../../../database/dbclient.js";
import { labelRatio } from "../../../../../database/schema/ratios.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
@@ -51,3 +51,34 @@ export const manualLabelCreated = async () => {
);
}
};
export const resetLabelRatio = async () => {
const { error } = await tryCatch(
db
.update(labelRatio)
.set({
name: sql`'label-' || (SELECT count(*) FROM ${labelRatio})`,
lastReset: sql`NOW()`,
})
.where(eq(labelRatio.name, "label"))
);
if (error) {
console.log(error);
createLog(
"error",
"labeling",
"ocp",
"There was an error resetting Label Ratio"
);
return {
success: false,
message: "There was an issue resetting the label data.",
};
}
return {
success: true,
message: "Label Ratio has been reset.",
};
};

View File

@@ -22,6 +22,8 @@ import AutostartPrinterCycle from "./routes/printers/autoLabelerStart.js";
import AutostopPrinterCycle from "./routes/printers/autoLabelerStop.js";
import { deleteLabels } from "../../globalUtils/dbCleanUp/labelCleanUp.js";
import bookInLabel from "./routes/labeling/bookIn.js";
import labelRatio from "./routes/labeling/getLabelRatio.js";
import resetRatio from "./routes/labeling/resetLabelRatio.js";
const app = new OpenAPIHono();
@@ -40,6 +42,8 @@ const routes = [
getLabels,
manualprint,
bookInLabel,
labelRatio,
resetRatio,
//dyco
dycoCon,
dycoClose,

View File

@@ -31,7 +31,6 @@ app.openapi(
return c.json({
success: labelData.success,
message: labelData.message,
count: labelData.count,
data: labelData.data,
});
}

View File

@@ -0,0 +1,38 @@
// an external way to creating logs
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
import { getLabelRatio } from "../../controller/labeling/getLabelRatio.js";
import { resetLabelRatio } from "../../controller/labeling/labelRatio.js";
const app = new OpenAPIHono({ strict: false });
app.openapi(
createRoute({
tags: ["ocp"],
summary: "Resets the label Ratio",
method: "post",
path: "/resetlabelratio",
responses: responses(),
}),
async (c) => {
const { data: labelData, error: labelError } = await tryCatch(
resetLabelRatio()
);
apiHit(c, { endpoint: "/labelratio" });
if (labelError) {
return c.json({
success: false,
message: "There was an error getting the printers",
});
}
return c.json({
success: labelData.success,
message: labelData.message,
});
}
);
export default app;