feat(silo attached detach): added in silo attach detach setup in the silo card

This commit is contained in:
2025-06-23 12:00:28 -05:00
parent d6d19f8e5b
commit 2ac48138cb
22 changed files with 1362 additions and 598 deletions

View File

@@ -41,15 +41,21 @@ export const postAdjustment = async (data: any, prod: any) => {
const { data: silo, error } = await tryCatch(
axios.post(url, siloAdjustment, {
headers: { Authorization: `Basic ${prod}` },
headers: {
"X-API-Key": process.env.TEC_API_KEY || "",
"Content-Type": "application/json",
},
})
);
let e = error as any;
if (e) {
console.log(e.response);
if (e.status === 401) {
const data = {
success: false,
message: "Incorrect alpla prod password.",
message: `There was error posting the data: ${JSON.stringify(
e.response?.data
)}`,
data: {
status: e.response?.status,
statusText: e.response?.statusText,

View File

@@ -0,0 +1,43 @@
import { runProdApi } from "../../../../globalUtils/runProdApi.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
export const attachSilo = async (data: any) => {
/**
* Detachs a silo
*/
const detachData = {
endpoint: "/public/v1.0/IssueMaterial/AssignSiloToMachine",
data: [
{
laneId: data.laneId,
machineId: data.machineId,
productionLotId: data.productionLotId,
},
],
};
const { data: d, error } = await tryCatch(runProdApi(detachData));
if (error) {
return {
success: false,
message: "Error processing attachingSilo data",
data: error,
};
}
if (!d.success) {
return {
success: false,
message: "Error processing silo attach data",
data: d.message,
};
}
return {
success: true,
message: "silo attach was completed",
data: d.data,
};
};

View File

@@ -0,0 +1,42 @@
import { runProdApi } from "../../../../globalUtils/runProdApi.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
export const detachSilo = async (data: any) => {
/**
* Detachs a silo
*/
const detachData = {
endpoint: "/public/v1.0/IssueMaterial/DetachSiloFromMachine",
data: [
{
laneId: data.laneId,
machineId: data.machineId,
},
],
};
const { data: d, error } = await tryCatch(runProdApi(detachData));
if (error) {
return {
success: false,
message: "Error processing detach data",
data: error,
};
}
if (!d.success) {
return {
success: false,
message: "Error processing detach data",
data: d.message,
};
}
return {
success: true,
message: "Detach was completed",
data: d.data,
};
};

View File

@@ -0,0 +1,63 @@
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { createLog } from "../../../logger/logger.js";
import { query } from "../../../sqlServer/prodSqlServer.js";
import {
connectedToMachine,
notconnectedToMachine,
} from "../../../sqlServer/querys/silo/connectionCheck.js";
type Data = {
siloID: string;
connectionType: string;
};
export const siloConnectionType = async (data: Data) => {
/**
* Will return the machines that are attached or detached based on the silo and connection type
*/
if (!data) {
return {
success: false,
message: "Missing mandatory data",
data: [{ error: "Missing siloId or ConnectionType" }],
};
}
// change the silo id to the correct one
let newQuery = "";
if (data.connectionType === "connected") {
newQuery = connectedToMachine.replace("[siloID]", data.siloID);
} else {
newQuery = notconnectedToMachine.replace("[siloID]", data.siloID);
}
/**
* get the silo data
*/
const { data: s, error } = (await tryCatch(
query(newQuery, "Silo connection check")
)) as any;
if (error) {
createLog(
"error",
"lst",
"logistics",
`There was an error getting the silo connection data: ${JSON.stringify(
error
)}`
);
return {
success: false,
message: "There was an error getting the silo connection data.",
data: error,
};
}
return {
success: true,
message: `silo ${data.connectionType} data`,
data: s.data,
};
};