Files
lst/lstV2/server/services/logistics/controller/commands/removeAsNonReusable.ts

51 lines
1.5 KiB
TypeScript

import { db } from "../../../../../database/dbclient.js";
import { commandLog } from "../../../../../database/schema/commandLog.js";
import { scanner } from "../../../../globalUtils/scannerConnect.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { query } from "../../../sqlServer/prodSqlServer.js";
import { labelInfo } from "../../../sqlServer/querys/warehouse/labelInfo.js";
export const removeAsNonReusable = async (data: any) => {
// get the label info
const { data: label, error: labelError } = (await tryCatch(
query(labelInfo.replaceAll("[runningNr]", data.runningNr), "Label Info"),
)) as any;
if (label.data[0].stockStatus === "notOnStock") {
return {
success: false,
message: `The label: ${data.runningNr} is not currently in stock`,
data: [],
};
}
if (label.data[0].blockingReason) {
return {
success: false,
status: 400,
message: `${data.runningNr} is currently blocked, to get this pallet removed please take the label to quality to be released then you can remove.`,
data: [],
};
}
await scanner.scan("AlplaPRODcmd23");
await scanner.scan(`${label.data[0].barcode}`);
let reason = data.reason || "";
delete data.reason;
const { data: commandL, error: ce } = await tryCatch(
db.insert(commandLog).values({
commandUsed: "removeAsNonReusable",
bodySent: data,
reasonUsed: reason,
}),
);
return {
success: true,
message: `The label: ${data.runningNr}, was removed`,
data: [],
};
};