refactor(ocme): cleaup on pickedup

This commit is contained in:
2025-03-25 07:54:22 -05:00
parent b9f19095cb
commit 73aa95a693

View File

@@ -1,89 +1,114 @@
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi"; import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import {postLabelData} from "../controller/postRunningNr.js"; import { postLabelData } from "../controller/postRunningNr.js";
import {apiHit} from "../../../globalUtils/apiHits.js"; import { apiHit } from "../../../globalUtils/apiHits.js";
import {pickedup} from "../controller/pickedup.js"; import { pickedup } from "../controller/pickedup.js";
const app = new OpenAPIHono(); const app = new OpenAPIHono();
const PostRunningNr = z.object({ const PostRunningNr = z.object({
sscc: z.string().optional().openapi({example: "00090103830005710997"}), sscc: z.string().optional().openapi({ example: "00090103830005710997" }),
runningNr: z.string().optional().openapi({example: "localhost"}), runningNr: z.string().optional().openapi({ example: "localhost" }),
areaFrom: z.string().optional().openapi({example: "The server we are going to connect to"}), areaFrom: z
completed: z.boolean().optional().openapi({example: true}), .string()
all: z.boolean().optional().openapi({example: false}), .optional()
.openapi({ example: "The server we are going to connect to" }),
completed: z.boolean().optional().openapi({ example: true }),
all: z.boolean().optional().openapi({ example: false }),
}); });
app.openapi( app.openapi(
createRoute({ createRoute({
tags: ["ocme"], tags: ["ocme"],
summary: "Picks up a pallet in the system.", summary: "Picks up a pallet in the system.",
method: "patch", method: "patch",
description: description:
"removes the pallet(s) from showing as needed to be picked up, we clear everything related to the pallet number to reduce the risk of a mix, passing `all` will just clear everything that is pending.", "removes the pallet(s) from showing as needed to be picked up, we clear everything related to the pallet number to reduce the risk of a mix, passing `all` will just clear everything that is pending.",
path: "/pickedup", path: "/pickedUp",
request: { request: {
body: { body: {
content: { content: {
"application/json": {schema: PostRunningNr}, "application/json": { schema: PostRunningNr },
},
},
}, },
responses: { },
200: { },
content: { responses: {
"application/json": { 200: {
schema: z.object({ content: {
success: z.boolean().openapi({example: true}), "application/json": {
message: z.string().openapi({example: "Starter"}), schema: z.object({
// data: z success: z.boolean().openapi({ example: true }),
// .array(z.object({sscc: z.string().optional()})) message: z.string().openapi({ example: "Starter" }),
// .optional() // data: z
// .openapi({example: []}), // .array(z.object({sscc: z.string().optional()}))
}), // .optional()
}, // .openapi({example: []}),
}, }),
description: "Response message", },
},
400: {
content: {
"application/json": {
schema: z.object({
success: z.boolean().openapi({example: false}),
message: z.string().optional().openapi({example: "Internal Server error"}),
data: z.array(z.object({})).optional().openapi({example: []}),
}),
},
},
description: "Internal Server Error",
},
// 401: {
// content: {
// "application/json": {
// schema: z.object({message: z.string().optional().openapi({example: "Unauthenticated"})}),
// },
// },
// description: "Unauthorized",
// },
500: {
content: {
"application/json": {
schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}),
},
},
description: "Internal Server Error",
},
}, },
}), description: "Response message",
async (c) => { },
// make sure we have a vaid user being accessed thats really logged in 400: {
try { content: {
const data = await c.req.json(); "application/json": {
apiHit(c, {endpoint: "api/ocme/pickedup", lastBody: data}); schema: z.object({
const postPallet = await pickedup(data); success: z.boolean().openapi({ example: false }),
return c.json({success: postPallet.success, message: postPallet.message, data: postPallet.data}, 200); message: z
} catch (error) { .string()
return c.json({success: false, message: "There was an error getting ocmeInfo data", data: error}, 400); .optional()
} .openapi({ example: "Internal Server error" }),
data: z.array(z.object({})).optional().openapi({ example: [] }),
}),
},
},
description: "Internal Server Error",
},
// 401: {
// content: {
// "application/json": {
// schema: z.object({message: z.string().optional().openapi({example: "Unauthenticated"})}),
// },
// },
// description: "Unauthorized",
// },
500: {
content: {
"application/json": {
schema: z.object({
message: z
.string()
.optional()
.openapi({ example: "Internal Server error" }),
}),
},
},
description: "Internal Server Error",
},
},
}),
async (c) => {
// make sure we have a vaid user being accessed thats really logged in
try {
const data = await c.req.json();
apiHit(c, { endpoint: "api/ocme/pickedup", lastBody: data });
const postPallet = await pickedup(data);
return c.json(
{
success: postPallet.success,
message: postPallet.message,
data: postPallet.data,
},
200
);
} catch (error) {
return c.json(
{
success: false,
message: "There was an error getting ocmeInfo data",
data: error,
},
400
);
} }
}
); );
export default app; export default app;