feat(helpercommand): bookin pallets
This commit is contained in:
@@ -9,6 +9,7 @@ import { eq, sql } from "drizzle-orm";
|
||||
export const bookInLabel = async (data: any) => {
|
||||
// update sscc so we can book in
|
||||
const SSCC = data.SSCC.slice(2);
|
||||
|
||||
// api url
|
||||
const url = await prodEndpointCreation(
|
||||
"/public/v1.1/Manufacturing/ProductionControlling/BookIn"
|
||||
@@ -33,7 +34,9 @@ export const bookInLabel = async (data: any) => {
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`${data.printer[0].name}, Error:${res.data}`
|
||||
`${
|
||||
data.printer ? data.printer[0].name : "Manual book in"
|
||||
}, Error:${res.data}`
|
||||
);
|
||||
//printerUpdate(data.printer, 7, "Error while booking in.");
|
||||
|
||||
@@ -43,7 +46,6 @@ export const bookInLabel = async (data: any) => {
|
||||
data: res.data,
|
||||
};
|
||||
}
|
||||
|
||||
// update the label.
|
||||
try {
|
||||
const booked = await db
|
||||
@@ -61,7 +63,7 @@ export const bookInLabel = async (data: any) => {
|
||||
"info",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`${booked[0].runningNr} , was just booked in.`
|
||||
`${parseInt(data.SSCC.slice(10, -1))} , was just booked in.`
|
||||
);
|
||||
|
||||
return {
|
||||
@@ -72,24 +74,35 @@ export const bookInLabel = async (data: any) => {
|
||||
data: { SSCC: data.SSCC },
|
||||
};
|
||||
} catch (error) {
|
||||
//console.log(error);
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`Error creating new runningNumber in the DB.`
|
||||
);
|
||||
return {
|
||||
success: true,
|
||||
message: `${parseInt(
|
||||
data.SSCC.slice(10, -1)
|
||||
)}, encoutnered an error posting to the db`,
|
||||
data: error,
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`${data.printer[0].name}, "Error: ${error}`
|
||||
`${
|
||||
data.printer ? data.printer[0].name : "Manual book in"
|
||||
}, "Error: ${error}`
|
||||
);
|
||||
// console.log(error.response.data);
|
||||
return {
|
||||
success: false,
|
||||
message: "There was an error booking in the label.",
|
||||
data: error,
|
||||
data: error.response.data,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
57
server/services/ocp/routes/labeling/bookIn.ts
Normal file
57
server/services/ocp/routes/labeling/bookIn.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
// 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";
|
||||
import { bookInLabel } from "../../controller/labeling/bookIn.js";
|
||||
import { createSSCC } from "../../../../globalUtils/createSSCC.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp"],
|
||||
summary: "Manual bookin by running Number",
|
||||
method: "post",
|
||||
path: "/bookin",
|
||||
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",
|
||||
});
|
||||
}
|
||||
|
||||
// get the sscc number
|
||||
const sscc = await createSSCC(bodyData.runningNr);
|
||||
|
||||
const { data: bookinLabel, error: bookInError } = await tryCatch(
|
||||
bookInLabel({ SSCC: sscc })
|
||||
);
|
||||
|
||||
if (bookInError) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "There was an error booking in the label.",
|
||||
data: bookInError,
|
||||
});
|
||||
}
|
||||
|
||||
const newLabel: any = bookinLabel;
|
||||
//console.log(newLabel);
|
||||
|
||||
return c.json({
|
||||
success: newLabel.success,
|
||||
message: newLabel.message,
|
||||
data: newLabel.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
Reference in New Issue
Block a user