added relocate
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import axios from "axios";
|
||||
import { db } from "../../../../../database/dbclient.js";
|
||||
import { commandLog } from "../../../../../database/schema/commandLog.js";
|
||||
import { createSSCC } from "../../../../globalUtils/createSSCC.js";
|
||||
import { prodEndpointCreation } from "../../../../globalUtils/createUrl.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { createLog } from "../../../logger/logger.js";
|
||||
|
||||
type Data = {
|
||||
runningNr: number;
|
||||
laneID: number;
|
||||
};
|
||||
export const relatePallet = async (data: Data) => {
|
||||
const { runningNr, laneID } = data;
|
||||
// replace the rn
|
||||
|
||||
// console.log(data);
|
||||
// create the url to post
|
||||
const url = await prodEndpointCreation("/public/v1.0/Warehousing/Relocate");
|
||||
const SSCC = await createSSCC(runningNr);
|
||||
const consumeSomething = {
|
||||
ScannerId: 999,
|
||||
laneId: laneID,
|
||||
sscc: SSCC.slice(2),
|
||||
};
|
||||
|
||||
console.log(consumeSomething);
|
||||
try {
|
||||
const results = await axios.post(url, consumeSomething, {
|
||||
headers: {
|
||||
"X-API-Key": process.env.TEC_API_KEY || "",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (results.data.Errors) {
|
||||
return {
|
||||
success: false,
|
||||
message: results.data.Errors.Error.Description,
|
||||
};
|
||||
}
|
||||
|
||||
if (results.data.Result !== 0) {
|
||||
return {
|
||||
success: false,
|
||||
message: results.data.Message,
|
||||
};
|
||||
}
|
||||
|
||||
const { data: commandL, error: ce } = await tryCatch(
|
||||
db.insert(commandLog).values({
|
||||
commandUsed: "relocate",
|
||||
bodySent: data,
|
||||
}),
|
||||
);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Pallet Was Relocated",
|
||||
status: results.status,
|
||||
};
|
||||
} catch (error: any) {
|
||||
console.log(error);
|
||||
return {
|
||||
success: false,
|
||||
status: 200,
|
||||
message: error.response?.data.errors[0].message,
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user