refactor(server): moved the server files outside the src to improve static files

This commit is contained in:
2025-03-01 15:23:42 -06:00
parent d3acdfb481
commit 89a2b3ea9e
28 changed files with 4592 additions and 2253 deletions

View File

@@ -0,0 +1,66 @@
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
import {modules} from "../../../../database/schema/modules.js";
import {db} from "../../../../database/dbclient.js";
import {eq} from "drizzle-orm";
// Define the request body schema
const requestSchema = z.object({
ip: z.string().optional(),
endpoint: z.string().optional(),
action: z.string().optional(),
stats: z.string().optional(),
});
// Define the response schema
const responseSchema = z.object({
message: z.string().optional(),
module_id: z.string().openapi({example: "6c922c6c-7de3-4ec4-acb0-f068abdc"}).optional(),
name: z.string().openapi({example: "Production"}).optional(),
active: z.boolean().openapi({example: true}).optional(),
roles: z.string().openapi({example: `["viewer","technician"]`}).optional(),
});
const app = new OpenAPIHono();
app.openapi(
createRoute({
tags: ["server"],
summary: "Returns all modules in the server",
method: "get",
path: "/",
responses: {
200: {
content: {
"application/json": {schema: responseSchema},
},
description: "Response message",
},
},
}),
async (c) => {
//console.log("system modules");
let module: any = [];
try {
module = await db.select().from(modules).where(eq(modules.active, true));
} catch (error) {
console.log(error);
module = [];
}
// parse the roles
const updateModules = module.map((m: any) => {
if (m.roles) {
return {...m, roles: JSON.parse(m?.roles)};
}
return m;
}); //JSON.parse(module[0]?.roles);
// Return response with the received data
return c.json({
message: `All active modules`,
data: updateModules,
});
}
);
export default app;

View File

@@ -0,0 +1,7 @@
import {OpenAPIHono} from "@hono/zod-openapi";
import modules from "./route/modules.js";
const app = new OpenAPIHono().route("server/modules", modules);
export default app;