feat(ocp): create and book in plus dyco controller implemented
This commit is contained in:
89
server/services/ocp/controller/labeling/bookIn.ts
Normal file
89
server/services/ocp/controller/labeling/bookIn.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import axios from "axios";
|
||||
import { prodEndpointCreation } from "../../../../globalUtils/createUrl.js";
|
||||
import { lstAuth } from "../../../../index.js";
|
||||
import { createLog } from "../../../logger/logger.js";
|
||||
import { db } from "../../../../../database/dbclient.js";
|
||||
import { prodlabels } from "../../../../../database/schema/prodLabels.js";
|
||||
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.0/Warehousing/BookIn");
|
||||
|
||||
// create bookin
|
||||
const newBookin = {
|
||||
scannerId: 777,
|
||||
sscc: SSCC,
|
||||
};
|
||||
|
||||
try {
|
||||
const res = await axios.post(url, newBookin, {
|
||||
headers: {
|
||||
Authorization: `Basic ${lstAuth}`,
|
||||
accept: "text/plain",
|
||||
},
|
||||
});
|
||||
|
||||
if (res.data.Result !== 0) {
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`${data.printer.name}, Error:${res.data.Message}`
|
||||
);
|
||||
//printerUpdate(data.printer, 7, "Error while booking in.");
|
||||
|
||||
return {
|
||||
success: false,
|
||||
message: "There was an error booking in the label.",
|
||||
data: res.data,
|
||||
};
|
||||
}
|
||||
|
||||
// update the label.
|
||||
try {
|
||||
await db
|
||||
.update(prodlabels)
|
||||
.set({
|
||||
status: "Booked in",
|
||||
upd_date: sql`NOW()`,
|
||||
})
|
||||
.where(
|
||||
eq(prodlabels.runningNr, parseInt(data.SSCC.slice(10, -1)))
|
||||
);
|
||||
} catch (error) {
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`Error creating new runningNumber in the DB.`
|
||||
);
|
||||
}
|
||||
|
||||
// label was booked in
|
||||
createLog(
|
||||
"info",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`${parseInt(data.SSCC.slice(10, -1))}, was just booked in`
|
||||
);
|
||||
return {
|
||||
success: true,
|
||||
message: `${parseInt(data.SSCC.slice(10, -1))}, was just booked in`,
|
||||
};
|
||||
} catch (error) {
|
||||
createLog(
|
||||
"error",
|
||||
"labeling",
|
||||
"ocp",
|
||||
`${data.printer.name}, "Error: ${error}`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: "There was an error booking in the label.",
|
||||
data: error,
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user