refactor(lottransfer): formatting changes

This commit is contained in:
2025-10-30 10:24:22 -05:00
parent c552b9eb1c
commit a19b03b8bf

View File

@@ -1,14 +1,14 @@
import { format, formatDuration, intervalToDuration } from "date-fns";
import { eq } from "drizzle-orm";
import { success } from "zod/v4";
import { db } from "../../../../../database/dbclient.js";
import { printerData } from "../../../../../database/schema/printers.js";
import { runProdApi } from "../../../../globalUtils/runProdApi.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { createLog } from "../../../logger/logger.js";
import { query } from "../../../sqlServer/prodSqlServer.js";
import { labelInfo } from "../../../sqlServer/querys/warehouse/labelInfo.js";
import { format, formatDuration, intervalToDuration } from "date-fns";
import { shiftChange } from "../../../sqlServer/querys/misc/shiftChange.js";
import { success } from "zod/v4";
import { labelInfo } from "../../../sqlServer/querys/warehouse/labelInfo.js";
type NewLotData = {
runningNumber: number;
@@ -58,8 +58,8 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
data.runningNumber
} is pending to be transfered already, remaining time ${formatDuration(
duration,
{ format: ["hours", "minutes", "seconds"] }
)}`
{ format: ["hours", "minutes", "seconds"] },
)}`,
);
return {
success: false,
@@ -67,14 +67,14 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
data.runningNumber
} is pending to be transfered already, remaining time ${formatDuration(
duration,
{ format: ["hours", "minutes", "seconds"] }
{ format: ["hours", "minutes", "seconds"] },
)}`,
data: [],
};
}
// get the shift time
const { data: shift, error: shiftError } = (await tryCatch(
query(shiftChange, "shift change from material.")
query(shiftChange, "shift change from material."),
)) as any;
if (shiftError) {
@@ -82,7 +82,7 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
"error",
"materials",
"ocp",
"There was an error getting the shift times will use fallback times"
"There was an error getting the shift times will use fallback times",
);
}
@@ -100,7 +100,7 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
shiftTimeSplit.length > 0 ? parseInt(shiftTimeSplit[0]) : 5, // this will parse the hour to remove teh zero
shiftTimeSplit.length > 0 ? parseInt(shiftTimeSplit[1]) : 3,
0,
0
0,
);
console.log("target", target.toLocaleString(), "Now", now.toLocaleString());
@@ -113,7 +113,7 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
shiftTimeSplit.length > 0 ? parseInt(shiftTimeSplit[0]) - 1 : 5, // this will parse the hour to remove teh zero
shiftTimeSplit.length > 0 ? parseInt(shiftTimeSplit[1]) : 0,
0,
0
0,
);
console.log("early", early.toLocaleString(), "Now", now.toLocaleString());
@@ -126,14 +126,14 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
shiftTimeSplit.length > 0 ? parseInt(shiftTimeSplit[0]) - 1 : 5, // this will parse the hour to remove teh zero
shiftTimeSplit.length > 0 ? parseInt(shiftTimeSplit[1]) : 0,
0,
0
0,
);
console.log(
"nextMonth",
nextMonth.toLocaleString(),
"Now",
now.toLocaleString()
now.toLocaleString(),
);
// console.log(early, target);
@@ -145,14 +145,14 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
"ocp",
`Eom transfers is not allowed right now please try again at ${format(
nextMonth,
"M/d/yyyy hh:mm"
)} `
"M/d/yyyy hh:mm",
)} `,
);
return {
success: false,
message: `Eom transfers is not allowed right now please try again at ${format(
nextMonth,
"M/d/yyyy hh:mm"
"M/d/yyyy hh:mm",
)} `,
data: [],
};
@@ -163,8 +163,8 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
const { data: label, error: labelError } = (await tryCatch(
query(
labelInfo.replace("[runningNr]", `${data.runningNumber}`),
"Get label info"
)
"Get label info",
),
)) as any;
if (labelError) {
@@ -172,7 +172,7 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
"error",
"materials",
"ocp",
"There was an error getting the label info"
"There was an error getting the label info",
);
return {
success: false,
@@ -186,7 +186,7 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
"error",
"materials",
"ocp",
`${data.runningNumber}: dose not exist or no longer in stock.`
`${data.runningNumber}: dose not exist or no longer in stock.`,
);
return {
success: false,
@@ -202,7 +202,7 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
"error",
"materials",
"ocp",
`${data.runningNumber}: currently in stock and not consumed to a lot.`
`${data.runningNumber}: currently in stock and not consumed to a lot.`,
);
return {
success: false,
@@ -213,7 +213,7 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
// get the pdf24 printer id
const { data: printer, error: printerError } = (await tryCatch(
db.select().from(printerData).where(eq(printerData.name, "PDF24"))
db.select().from(printerData).where(eq(printerData.name, "PDF24")),
)) as any;
if (printerError) {
@@ -221,7 +221,7 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
"error",
"materials",
"ocp",
"There was an error the printer info"
"There was an error the printer info",
);
return {
success: false,
@@ -254,7 +254,7 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
runProdApi({
endpoint: "/public/v1.0/ProductionLabelling/ReprintLabel",
data: [reprintData],
})
}),
)) as any;
if (!reprint.success) {
@@ -262,7 +262,7 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
"error",
"materials",
"ocp",
`RN:${data.runningNumber}, Reprinting Error: ${reprint.data.data.message}`
`RN:${data.runningNumber}, Reprinting Error: ${reprint.data.data.message}`,
);
return {
success: false,
@@ -283,7 +283,7 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
endpoint:
"/public/v1.0/IssueMaterial/ReturnPartiallyConsumedManualMaterial",
data: [matReturnData],
})
}),
)) as any;
if (!matReturn.success) {
@@ -291,7 +291,7 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
"error",
"materials",
"ocp",
`RN:${data.runningNumber}, Return Error ${matReturn.data.data.errors[0].message}`
`RN:${data.runningNumber}, Return Error ${matReturn.data.data.errors[0].message}`,
);
return {
success: false,
@@ -344,7 +344,7 @@ const transferMaterial = async (
delay: number,
data: any,
consumeLot: any,
newQty: any
newQty: any,
) => {
//console.log(data);
if (pendingJobs.has(data.runningNumber)) {
@@ -352,7 +352,7 @@ const transferMaterial = async (
"error",
"materials",
"ocp",
`${data.runningNumber} is pending to be transfered already`
`${data.runningNumber} is pending to be transfered already`,
);
return {
success: false,
@@ -365,13 +365,12 @@ const transferMaterial = async (
// sets the time out based on the type of transfer sent over.
const timeoutId = setTimeout(async () => {
try {
const { data: matConsume, error: matConsumeError } =
(await tryCatch(
const { data: matConsume, error: matConsumeError } = (await tryCatch(
runProdApi({
endpoint:
"/public/v1.0/IssueMaterial/ConsumeNonPreparedManualMaterial",
data: [consumeLot],
})
}),
)) as any;
if (!matConsume?.success) {
@@ -380,9 +379,8 @@ const transferMaterial = async (
"materials",
"ocp",
`RN:${data.runningNumber}, Consume Error ${
matConsume?.data?.data?.errors?.[0]?.message ??
"Unknown"
}`
matConsume?.data?.data?.errors?.[0]?.message ?? "Unknown"
}`,
);
return; // still hits finally
}
@@ -391,14 +389,14 @@ const transferMaterial = async (
"info",
"materials",
"ocp",
`RN:${data.runningNumber}: qty: ${newQty}, was transferred to lot:${data.lotNumber}`
`RN:${data.runningNumber}: qty: ${newQty}, was transferred to lot:${data.lotNumber}`,
);
} catch (err) {
createLog(
"error",
"materials",
"ocp",
`RN:${data.runningNumber}, ${err}`
`RN:${data.runningNumber}, ${err}`,
);
} finally {
// Always clear the pending entry, even if error