feat(ocp): create and book in plus dyco controller implemented
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { responses } from "../../../../../globalUtils/routeDefs/responses.js";
|
||||
import { authMiddleware } from "../../../../auth/middleware/authMiddleware.js";
|
||||
import { tryCatch } from "../../../../../globalUtils/tryCatch.js";
|
||||
import { closeDyco } from "../../../controller/specialProcesses/dyco/plcConnection.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp:dyco"],
|
||||
summary: "Disconnect to the dyco.",
|
||||
method: "get",
|
||||
path: "/dycodisconnect",
|
||||
middleware: authMiddleware,
|
||||
description:
|
||||
"Use this when you just want to stop the entire thing due to an error or what not.",
|
||||
// request: {
|
||||
// body: {content: {"application/json": {schema: CreateLog}}},
|
||||
// },
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
//const body = await c.req.json();
|
||||
//apiHit(c, {endpoint: `api/logger/logs/id`});
|
||||
// const authHeader = c.req.header("Authorization");
|
||||
|
||||
// const token = authHeader?.split("Bearer ")[1] || "";
|
||||
// let user: User;
|
||||
|
||||
// try {
|
||||
// const payload = await verify(token, process.env.JWT_SECRET!);
|
||||
// user = payload.user as User;
|
||||
// } catch (error) {
|
||||
// console.log(error);
|
||||
// return c.json({message: "Unauthorized"}, 401);
|
||||
// }
|
||||
|
||||
const { data, error } = await tryCatch(closeDyco());
|
||||
|
||||
if (error) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "Error in connecting to dyco",
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
const getData: any = data;
|
||||
return c.json({
|
||||
success: getData?.success,
|
||||
message: getData?.message,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
@@ -0,0 +1,56 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { responses } from "../../../../../globalUtils/routeDefs/responses.js";
|
||||
import { authMiddleware } from "../../../../auth/middleware/authMiddleware.js";
|
||||
import { tryCatch } from "../../../../../globalUtils/tryCatch.js";
|
||||
import { dycoConnect } from "../../../controller/specialProcesses/dyco/plcConnection.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp:dyco"],
|
||||
summary: "Connects to the dyco.",
|
||||
method: "get",
|
||||
path: "/dycoconnect",
|
||||
middleware: authMiddleware,
|
||||
//description: "This might be a temp soltuin during the transtion between versions",
|
||||
// request: {
|
||||
// body: {content: {"application/json": {schema: CreateLog}}},
|
||||
// },
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
//const body = await c.req.json();
|
||||
//apiHit(c, {endpoint: `api/logger/logs/id`});
|
||||
// const authHeader = c.req.header("Authorization");
|
||||
|
||||
// const token = authHeader?.split("Bearer ")[1] || "";
|
||||
// let user: User;
|
||||
|
||||
// try {
|
||||
// const payload = await verify(token, process.env.JWT_SECRET!);
|
||||
// user = payload.user as User;
|
||||
// } catch (error) {
|
||||
// console.log(error);
|
||||
// return c.json({message: "Unauthorized"}, 401);
|
||||
// }
|
||||
|
||||
const { data, error } = await tryCatch(dycoConnect());
|
||||
const dataError: any = error;
|
||||
if (error) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "Error in connecting to dyco",
|
||||
data: dataError?.data,
|
||||
});
|
||||
}
|
||||
const getData: any = data;
|
||||
return c.json({
|
||||
success: getData?.success,
|
||||
message: getData?.message,
|
||||
data: getData.data ?? [],
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
Reference in New Issue
Block a user