refactor(dockscanning): more work on the dock door scanning
All checks were successful
Build and Push LST Docker Image / docker (push) Successful in 1m47s
All checks were successful
Build and Push LST Docker Image / docker (push) Successful in 1m47s
ref #12
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../db/db.controller.js";
|
||||
import { dockDoorScans } from "../db/schema/dockdoor.scans.schema.js";
|
||||
import { dockDoorScanners } from "../db/schema/dockdoor.schema.js";
|
||||
import { emitToRoom } from "../socket.io/roomEmitter.socket.js";
|
||||
import { runProdApi } from "../utils/prodEndpoint.utils.js";
|
||||
@@ -15,12 +16,35 @@ type Data = {
|
||||
runningNo?: string;
|
||||
};
|
||||
|
||||
const postScan = async (data: any) => {
|
||||
try {
|
||||
await db.insert(dockDoorScans).values({
|
||||
dockId: data.dockId,
|
||||
loadingOrder: data.loadingOrder,
|
||||
loadingUnit: data.unit, // can be running number or sscc depending on where it came from
|
||||
loadingUnitStatus: data.unitStatus, // TODO: add enums on the status of each load.
|
||||
message: data.message, // the response it gave when scanning
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("Error: ", error);
|
||||
}
|
||||
};
|
||||
|
||||
const loadUnit = async (data: Data) => {
|
||||
// are we even active at this time?
|
||||
const dockDoorActive = await db.query.settings.findFirst({
|
||||
where: (u, { eq }) => eq(u.name, "dockDoorScanning"),
|
||||
});
|
||||
|
||||
const unitToScan = data.sscc
|
||||
? { sscc: data.sscc?.slice(2) }
|
||||
: { runningNo: Number(data.runningNo) };
|
||||
|
||||
const dock = await db
|
||||
.select()
|
||||
.from(dockDoorScanners)
|
||||
.where(eq(dockDoorScanners.dockId, data.dockId as string));
|
||||
|
||||
if (!dockDoorActive?.active) {
|
||||
return returnFunc({
|
||||
success: false,
|
||||
@@ -33,29 +57,18 @@ const loadUnit = async (data: Data) => {
|
||||
room: "",
|
||||
});
|
||||
}
|
||||
// check if its a valids an sscc
|
||||
|
||||
if (data.sscc === "noread") {
|
||||
return returnFunc({
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "dockdoor",
|
||||
subModule: "loadUnit",
|
||||
message:
|
||||
"Failed to load the unit to the truck, there was no pallet read.",
|
||||
data: [],
|
||||
notify: false,
|
||||
room: `dockDoorLoading:${data.dockId}`,
|
||||
});
|
||||
}
|
||||
|
||||
// check if we currently have a loading order attached to the dock door.
|
||||
const dock = await db
|
||||
.select()
|
||||
.from(dockDoorScanners)
|
||||
.where(eq(dockDoorScanners.dockId, data.dockId as string));
|
||||
|
||||
if (dock[0]?.currentLoadingOrder === "") {
|
||||
postScan({
|
||||
dockId: data.dockId,
|
||||
loadingOrder: dock[0]?.currentLoadingOrder,
|
||||
loadingUnit: unitToScan,
|
||||
loadingUnitStatus: "notLoaded",
|
||||
message:
|
||||
"There are know current active loading orders please start one and try again.",
|
||||
});
|
||||
return returnFunc({
|
||||
success: true,
|
||||
level: "error",
|
||||
@@ -68,6 +81,30 @@ const loadUnit = async (data: Data) => {
|
||||
room: `dockDoorLoading:${data.dockId}`,
|
||||
});
|
||||
}
|
||||
// check if its a valids an sscc
|
||||
|
||||
if (data.sscc === "noread") {
|
||||
postScan({
|
||||
dockId: data.dockId,
|
||||
loadingOrder: dock[0]?.currentLoadingOrder,
|
||||
loadingUnit: unitToScan,
|
||||
loadingUnitStatus: "noread",
|
||||
message:
|
||||
"Failed to load the unit to the truck, there was no pallet read.",
|
||||
});
|
||||
|
||||
return returnFunc({
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "dockdoor",
|
||||
subModule: "loadUnit",
|
||||
message:
|
||||
"Failed to load the unit to the truck, there was no pallet read.",
|
||||
data: [],
|
||||
notify: false,
|
||||
room: `dockDoorLoading:${data.dockId}`,
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: pallet validation, check if we are on hold, then check if we have been in the staging warehouse for more than x time.
|
||||
|
||||
@@ -77,10 +114,6 @@ const loadUnit = async (data: Data) => {
|
||||
|
||||
// add the loading units
|
||||
try {
|
||||
const unitToScan = data.sscc
|
||||
? { sscc: data.sscc?.slice(2) }
|
||||
: { runningNo: Number(data.runningNo) };
|
||||
|
||||
const prod = (await runProdApi({
|
||||
method: "post",
|
||||
endpoint: `/public/v1.0/OutboundDeliveries/LoadingOrders/${dock[0]?.currentLoadingOrder}/LoadUnit`,
|
||||
@@ -90,6 +123,13 @@ const loadUnit = async (data: Data) => {
|
||||
//emitToRoom(`dockDoorLoading:${data.dockId}`, prod?.data ?? []);
|
||||
|
||||
if (!prod?.success) {
|
||||
postScan({
|
||||
dockId: data.dockId,
|
||||
loadingOrder: dock[0]?.currentLoadingOrder,
|
||||
loadingUnit: unitToScan,
|
||||
loadingUnitStatus: "notLoaded",
|
||||
message: prod?.data.errors[0].message,
|
||||
});
|
||||
emitToRoom(`dockDoorLoading:${data.dockId}`, prod?.data.errors[0]);
|
||||
return returnFunc({
|
||||
success: false,
|
||||
@@ -107,6 +147,14 @@ const loadUnit = async (data: Data) => {
|
||||
data: prod.data,
|
||||
code: 0,
|
||||
};
|
||||
|
||||
postScan({
|
||||
dockId: data.dockId,
|
||||
loadingOrder: dock[0]?.currentLoadingOrder,
|
||||
loadingUnit: unitToScan,
|
||||
loadingUnitStatus: "loaded",
|
||||
message: emitData.message,
|
||||
});
|
||||
emitToRoom(`dockDoorLoading:${data.dockId}`, emitData as any);
|
||||
return returnFunc({
|
||||
success: true,
|
||||
|
||||
Reference in New Issue
Block a user