66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
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;
|