feat(silo attached detach): added in silo attach detach setup in the silo card
This commit is contained in:
92
server/globalUtils/runProdApi.ts
Normal file
92
server/globalUtils/runProdApi.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
import axios from "axios";
|
||||
import { prodEndpointCreation } from "./createUrl.js";
|
||||
import { tryCatch } from "./tryCatch.js";
|
||||
import { createLog } from "../services/logger/logger.js";
|
||||
|
||||
type bodyData = any;
|
||||
|
||||
type Data = {
|
||||
endpoint: string;
|
||||
data: bodyData[];
|
||||
};
|
||||
export const runProdApi = async (data: Data) => {
|
||||
/**
|
||||
* Detachs a silo
|
||||
*/
|
||||
|
||||
let url = await prodEndpointCreation(data.endpoint);
|
||||
|
||||
const { data: d, error } = await tryCatch(
|
||||
axios.post(url, data.data[0], {
|
||||
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) {
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"logistics",
|
||||
`Not autorized: ${JSON.stringify(e.response?.data)}`
|
||||
);
|
||||
const data = {
|
||||
success: false,
|
||||
message: `Not autorized: ${JSON.stringify(e.response?.data)}`,
|
||||
data: {
|
||||
status: e.response?.status,
|
||||
statusText: e.response?.statusText,
|
||||
data: e.response?.data,
|
||||
},
|
||||
};
|
||||
return data;
|
||||
} else {
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"logistics",
|
||||
`There was an error processing the endpoint: ${JSON.stringify(
|
||||
e.response?.data
|
||||
)}`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
message: `There was an error processing the endpoint: ${JSON.stringify(
|
||||
e.response?.data
|
||||
)}`,
|
||||
data: {
|
||||
status: e.response?.status,
|
||||
statusText: e.response?.statusText,
|
||||
data: e.response?.data,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (d?.status !== 200) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Error processing endpoint",
|
||||
data: {
|
||||
status: d?.status,
|
||||
statusText: d?.statusText,
|
||||
data: d?.data,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: true,
|
||||
message: "Endpoint was processed",
|
||||
data: {
|
||||
status: d.status,
|
||||
statusText: d.statusText,
|
||||
data: d.data,
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
@@ -21,6 +21,9 @@ import intervalChecks from "./route/getActiveLogistics.js";
|
||||
import getActiveLanes from "./route/getActiveLanes.js";
|
||||
import removeAsNonReable from "./route/removeAsNonReusable.js";
|
||||
import getSSCC from "./route/getSSCCNumber.js";
|
||||
import getConnectionType from "./route/getSiloConnectionData.js";
|
||||
import detachSilo from "./route/detachSilo.js";
|
||||
import attachSilo from "./route/attachSilo.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
@@ -33,6 +36,9 @@ const routes = [
|
||||
postComment,
|
||||
getStockSilo,
|
||||
getSiloAdjustments,
|
||||
getConnectionType,
|
||||
detachSilo,
|
||||
attachSilo,
|
||||
//lanes
|
||||
getCycleCountCheck,
|
||||
//warehouse
|
||||
|
||||
65
server/services/logistics/route/attachSilo.ts
Normal file
65
server/services/logistics/route/attachSilo.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||
import { attachSilo } from "../controller/siloAttachments/attachSilo.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
// const Body = z
|
||||
// .object({
|
||||
// age: z.number().optional().openapi({ example: 90 }),
|
||||
// //email: z.string().optional().openapi({example: "s.smith@example.com"}),
|
||||
// type: z.string().optional().openapi({ example: "fg" }),
|
||||
// })
|
||||
// .openapi("User");
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["logistics"],
|
||||
summary: "Returns all the silo connection based on connection type",
|
||||
method: "post",
|
||||
path: "/attachsilo",
|
||||
// request: {
|
||||
// body: {
|
||||
// content: {
|
||||
// "application/json": { schema: Body },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// description:
|
||||
// "Provided a running number and lot number you can consume material.",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c: any) => {
|
||||
apiHit(c, { endpoint: "/attachSilo" });
|
||||
|
||||
const { data: body, error: bodyError } = await tryCatch(c.req.json());
|
||||
|
||||
if (bodyError) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Missing mandatory data",
|
||||
data: [{ error: "Missing Data" }],
|
||||
};
|
||||
}
|
||||
|
||||
let b = body as any;
|
||||
|
||||
const { data: silo, error } = await tryCatch(attachSilo(b));
|
||||
|
||||
if (error) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "Error detaching silo.",
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
|
||||
return c.json({
|
||||
success: silo.success,
|
||||
message: silo.message,
|
||||
data: silo.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
67
server/services/logistics/route/detachSilo.ts
Normal file
67
server/services/logistics/route/detachSilo.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||
|
||||
import { siloConnectionType } from "../controller/siloAttachments/siloConnectionData.js";
|
||||
import { detachSilo } from "../controller/siloAttachments/detachSilo.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
// const Body = z
|
||||
// .object({
|
||||
// age: z.number().optional().openapi({ example: 90 }),
|
||||
// //email: z.string().optional().openapi({example: "s.smith@example.com"}),
|
||||
// type: z.string().optional().openapi({ example: "fg" }),
|
||||
// })
|
||||
// .openapi("User");
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["logistics"],
|
||||
summary: "Returns all the silo connection based on connection type",
|
||||
method: "post",
|
||||
path: "/detachsilo",
|
||||
// request: {
|
||||
// body: {
|
||||
// content: {
|
||||
// "application/json": { schema: Body },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// description:
|
||||
// "Provided a running number and lot number you can consume material.",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c: any) => {
|
||||
apiHit(c, { endpoint: "/attachSilo" });
|
||||
|
||||
const { data: body, error: bodyError } = await tryCatch(c.req.json());
|
||||
|
||||
if (bodyError) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Missing mandatory data",
|
||||
data: [{ error: "Missing Data" }],
|
||||
};
|
||||
}
|
||||
|
||||
let b = body as any;
|
||||
|
||||
const { data: silo, error } = await tryCatch(detachSilo(b));
|
||||
|
||||
if (error) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "Error detaching silo.",
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
|
||||
return c.json({
|
||||
success: silo.success,
|
||||
message: silo.message,
|
||||
data: silo.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
66
server/services/logistics/route/getSiloConnectionData.ts
Normal file
66
server/services/logistics/route/getSiloConnectionData.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||
|
||||
import { siloConnectionType } from "../controller/siloAttachments/siloConnectionData.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
// const Body = z
|
||||
// .object({
|
||||
// age: z.number().optional().openapi({ example: 90 }),
|
||||
// //email: z.string().optional().openapi({example: "s.smith@example.com"}),
|
||||
// type: z.string().optional().openapi({ example: "fg" }),
|
||||
// })
|
||||
// .openapi("User");
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["logistics"],
|
||||
summary: "Returns all the silo connection based on connection type",
|
||||
method: "post",
|
||||
path: "/siloconnection",
|
||||
// request: {
|
||||
// body: {
|
||||
// content: {
|
||||
// "application/json": { schema: Body },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// description:
|
||||
// "Provided a running number and lot number you can consume material.",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c: any) => {
|
||||
apiHit(c, { endpoint: "/siloconnection" });
|
||||
|
||||
const { data: body, error: bodyError } = await tryCatch(c.req.json());
|
||||
|
||||
if (bodyError) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Missing mandatory data",
|
||||
data: [{ error: "Missing Data" }],
|
||||
};
|
||||
}
|
||||
|
||||
let b = body as any;
|
||||
|
||||
const { data: silo, error } = await tryCatch(siloConnectionType(b));
|
||||
|
||||
if (error) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "Error getting silo connection data.",
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
|
||||
return c.json({
|
||||
success: silo.success,
|
||||
message: silo.message,
|
||||
data: silo.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
42
server/services/sqlServer/querys/silo/connectionCheck.ts
Normal file
42
server/services/sqlServer/querys/silo/connectionCheck.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
export const notconnectedToMachine = `
|
||||
select distinct HumanReadableId as machineId
|
||||
,Location as location
|
||||
,name
|
||||
--,[SiloHumanReadableId]
|
||||
from [test1_AlplaPROD2.0_Read].[masterData].[Machine] (nolock) m
|
||||
|
||||
left join
|
||||
[test1_AlplaPROD2.0_Read].[issueMaterial].[SiloAssignment] (nolock) s
|
||||
on s.MachineId = m.id
|
||||
|
||||
|
||||
where m.id not in (
|
||||
SELECT
|
||||
[MachineId]
|
||||
|
||||
FROM [test1_AlplaPROD2.0_Read].[issueMaterial].[SiloAssignment]
|
||||
|
||||
where [SiloHumanReadableId] = [siloID]
|
||||
)
|
||||
|
||||
and name not like '%REWORK%'
|
||||
`;
|
||||
|
||||
export const connectedToMachine = `
|
||||
SELECT
|
||||
[SiloHumanReadableId]
|
||||
,[SiloDescription]
|
||||
,[MaterialHumanReadableId]
|
||||
,[MaterialDescription]
|
||||
,[ConnectionDate]
|
||||
,m.HumanReadableId as machineId
|
||||
,m.Location as location
|
||||
,m.Name as name
|
||||
FROM [test1_AlplaPROD2.0_Read].[issueMaterial].[SiloAssignment] s
|
||||
|
||||
left join
|
||||
[test1_AlplaPROD2.0_Read].[masterData].[Machine] m
|
||||
on m.id = s.MachineId
|
||||
|
||||
where [SiloHumanReadableId] = [siloID]
|
||||
`;
|
||||
Reference in New Issue
Block a user