fix(commands): corrections to allow external labels to be consumed and transfered

This commit is contained in:
2025-12-02 18:29:30 -06:00
parent 6833dfc992
commit 12345c0b64
4 changed files with 79 additions and 67 deletions

View File

@@ -5,11 +5,22 @@ meta {
} }
get { get {
url: url: {{url}}/lst/old/api/logger/logs?service=ocp&service=rfid&service=dyco&level=error&level=info&level=warn&hours=12
body: none body: none
auth: inherit auth: inherit
} }
params:query {
service: ocp
service: rfid
service: dyco
level: error
level: info
level: warn
hours: 12
}
settings { settings {
encodeUrl: true encodeUrl: true
timeout: 0
} }

View File

@@ -1,78 +1,78 @@
import axios from "axios"; import axios from "axios";
import { labelData } from "../../../sqlServer/querys/materialHelpers/labelInfo.js";
import { query } from "../../../sqlServer/prodSqlServer.js";
import { createLog } from "../../../logger/logger.js";
import { prodEndpointCreation } from "../../../../globalUtils/createUrl.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { db } from "../../../../../database/dbclient.js"; import { db } from "../../../../../database/dbclient.js";
import { commandLog } from "../../../../../database/schema/commandLog.js"; import { commandLog } from "../../../../../database/schema/commandLog.js";
import { prodEndpointCreation } from "../../../../globalUtils/createUrl.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { createLog } from "../../../logger/logger.js";
import { query } from "../../../sqlServer/prodSqlServer.js";
import { labelData } from "../../../sqlServer/querys/materialHelpers/labelInfo.js";
import { labelInfo } from "../../../sqlServer/querys/warehouse/labelInfo.js";
type Data = { type Data = {
runningNr: string; runningNr: string;
lotNum: number; lotNum: number;
}; };
export const consumeMaterial = async (data: Data) => { export const consumeMaterial = async (data: Data) => {
const { runningNr, lotNum } = data; const { runningNr, lotNum } = data;
// replace the rn // replace the rn
console.log(data); // console.log(data);
const rnReplace = labelData.replaceAll("[rn]", runningNr); const rnReplace = labelInfo.replaceAll("[runningNr]", runningNr);
let barcode; let barcode;
// get the barcode from the running number // get the barcode from the running number
try { try {
const r: any = await query(rnReplace, "labelData"); const r: any = await query(rnReplace, "labelData");
barcode = r?.data; //console.log(r);
} catch (error) { barcode = r?.data;
console.log(error); } catch (error) {
createLog("error", "", "logistics", `Error getting barcode: ${error}`); console.log(error);
} createLog("error", "", "logistics", `Error getting barcode: ${error}`);
}
if (barcode.length === 0) { if (barcode.length === 0) {
return { return {
success: false, success: false,
message: "The running number you've entered not on stock.", message: "The running number you've entered not on stock.",
}; };
//throw Error("The provided runningNr is not in stock"); //throw Error("The provided runningNr is not in stock");
} }
// create the url to post // create the url to post
const url = await prodEndpointCreation( const url = await prodEndpointCreation(
"/public/v1.0/IssueMaterial/ConsumeNonPreparedManualMaterial" "/public/v1.0/IssueMaterial/ConsumeNonPreparedManualMaterial",
); );
const consumeSomething = { const consumeSomething = {
productionLot: lotNum, productionLot: lotNum,
barcode: barcode[0]?.barcode, barcode: barcode[0]?.barcode,
}; };
try { try {
const results = await axios.post(url, consumeSomething, { const results = await axios.post(url, consumeSomething, {
headers: { headers: {
"X-API-Key": process.env.TEC_API_KEY || "", "X-API-Key": process.env.TEC_API_KEY || "",
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
const { data: commandL, error: ce } = await tryCatch( const { data: commandL, error: ce } = await tryCatch(
db.insert(commandLog).values({ db.insert(commandLog).values({
commandUsed: "consumeMaterial", commandUsed: "consumeMaterial",
bodySent: data, bodySent: data,
}) }),
); );
return { return {
success: true, success: true,
message: "Material was consumed", message: "Material was consumed",
status: results.status, status: results.status,
}; };
} catch (error: any) { } catch (error: any) {
console.log(error); console.log(error);
return { return {
success: false, success: false,
status: 200, status: 200,
message: error.response?.data.errors[0].message, message: error.response?.data.errors[0].message,
}; };
} }
}; };

View File

@@ -168,6 +168,7 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
), ),
)) as any; )) as any;
console.log(label);
if (labelError) { if (labelError) {
createLog( createLog(
"error", "error",
@@ -274,7 +275,7 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
// return the label back to fm1 lane id 10001 // return the label back to fm1 lane id 10001
const matReturnData = { const matReturnData = {
barcode: label?.data[0].Barcode, barcode: label?.data[0].barcode,
laneId: 10001, laneId: 10001,
}; };
@@ -300,7 +301,7 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
// consume to the lot provided. // consume to the lot provided.
const consumeLot = { const consumeLot = {
productionLot: data.lotNumber, productionLot: data.lotNumber,
barcode: label?.data[0].Barcode, barcode: label?.data[0].barcode,
}; };
const delayTimer = const delayTimer =

View File

@@ -1,7 +1,7 @@
export const labelInfo = ` export const labelInfo = `
declare @runningNumber nvarchar(max) = [runningNr] declare @runningNumber nvarchar(max) = [runningNr]
select e.Barcode, select e.barcode,
e.RunningNumber as runnungNumber, e.RunningNumber as runnungNumber,
externalRunningNumber= null, externalRunningNumber= null,
e.ArticleHumanReadableId as av, e.ArticleHumanReadableId as av,