refactor(ocp): lots of work for rfid and dyco contorl

This commit is contained in:
2025-03-27 21:12:22 -05:00
parent 27d6b6e884
commit ba3d721940
19 changed files with 360 additions and 162 deletions

View File

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

View File

@@ -0,0 +1,50 @@
// 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 { labelingProcess } from "../../controller/labeling/labelProcess.js";
const app = new OpenAPIHono({ strict: false });
app.openapi(
createRoute({
tags: ["ocp"],
summary: "Manual print a label by line and printer name",
method: "post",
path: "/manualprintandfollow",
responses: responses(),
}),
async (c) => {
//const hours = c.req.query("hours");
const { data: bodyData, error: bodyError } = await tryCatch(
c.req.json()
);
if (bodyError) {
return c.json({
success: false,
message: "You are missing data",
});
}
const { data: createLabel, error: labelError } = await tryCatch(
labelingProcess({ line: bodyData.line })
);
if (labelError) {
return c.json({
success: false,
message: "There was an error creating the label.",
data: labelError,
});
}
const newLabel: any = createLabel;
return c.json({
success: newLabel.success,
message: newLabel.message,
data: newLabel.data,
});
}
);
export default app;

View File

@@ -1,11 +1,12 @@
// an external way to creating logs
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { apiHit } from "../../../globalUtils/apiHits.js";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import type { User } from "../../../types/users.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import type { User } from "../../../../types/users.js";
import { verify } from "hono/jwt";
import { manualPrint } from "../controller/manualLabelLog.js";
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
import { manualPrint } from "../../controller/labeling/manualLabelLog.js";
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
const app = new OpenAPIHono({ strict: false });
const CreateLog = z.object({
@@ -32,7 +33,17 @@ app.openapi(
responses: responses(),
}),
async (c) => {
const body = await c.req.json();
const { data: body, error } = await tryCatch(c.req.json());
if (error) {
return c.json(
{
success: false,
message: "Missing Data.",
},
400
);
}
apiHit(c, { endpoint: `api/logger/logs/id` });
try {
//const data = {...body, add_user: user.username};

View File

@@ -1,52 +0,0 @@
// an external way to creating logs
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
import {apiHit} from "../../../globalUtils/apiHits.js";
import {responses} from "../../../globalUtils/routeDefs/responses.js";
const app = new OpenAPIHono({strict: false});
const CreateLog = z.object({
line: z.string().openapi({example: "info"}),
initials: z.string().openapi({example: "server"}),
printReason: z.string().openapi({example: "This is a new log posted"}),
additionalComments: z.string().optional().openapi({example: "Some reason why we did this."}),
});
app.openapi(
createRoute({
tags: ["ocp"],
summary: "Prints a label.",
method: "post",
path: "/printlabel",
//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 body = await c.req.json();
apiHit(c, {endpoint: `api/logger/logs/id`});
// const authHeader = c.req.header("Authorization");
// const token = authHeader?.split("Bearer ")[1] || "";
// let user: User;
// try {
// const payload = await verify(token, process.env.JWT_SECRET!);
// user = payload.user as User;
// } catch (error) {
// console.log(error);
// return c.json({message: "Unauthorized"}, 401);
// }
try {
//const data = {...body, add_user: user.username};
return c.json({success: true, message: "Label was printed.", data: []}, 200);
} catch (error) {
return c.json({success: false, message: "There was an error printing a label.", data: error}, 400);
}
}
);
export default app;