95 lines
2.7 KiB
TypeScript
95 lines
2.7 KiB
TypeScript
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.1/Manufacturing/ProductionControlling/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.status != 200) {
|
|
createLog(
|
|
"error",
|
|
"labeling",
|
|
"ocp",
|
|
`${data.printer[0].name}, Error:${res.data}`
|
|
);
|
|
//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 {
|
|
const booked = await db
|
|
.update(prodlabels)
|
|
.set({
|
|
status: "Booked in",
|
|
upd_date: sql`NOW()`,
|
|
})
|
|
.where(
|
|
eq(prodlabels.runningNr, parseInt(data.SSCC.slice(10, -1)))
|
|
)
|
|
.returning({ runningNr: prodlabels.runningNr });
|
|
|
|
createLog(
|
|
"info",
|
|
"labeling",
|
|
"ocp",
|
|
`${booked[0].runningNr} , was just booked in.`
|
|
);
|
|
|
|
return {
|
|
success: true,
|
|
message: `${parseInt(
|
|
data.SSCC.slice(10, -1)
|
|
)}, was just booked in`,
|
|
};
|
|
} catch (error) {
|
|
createLog(
|
|
"error",
|
|
"labeling",
|
|
"ocp",
|
|
`Error creating new runningNumber in the DB.`
|
|
);
|
|
}
|
|
} catch (error) {
|
|
createLog(
|
|
"error",
|
|
"labeling",
|
|
"ocp",
|
|
`${data.printer[0].name}, "Error: ${error}`
|
|
);
|
|
return {
|
|
success: false,
|
|
message: "There was an error booking in the label.",
|
|
data: error,
|
|
};
|
|
}
|
|
};
|