feat(submodules and login redirect): submodules added and login redirect

This commit is contained in:
2025-04-04 22:10:11 -05:00
parent f1abe7b33d
commit 85577b291f
15 changed files with 450 additions and 223 deletions

View File

@@ -2,9 +2,18 @@ import { OpenAPIHono } from "@hono/zod-openapi";
import comsumeMaterial from "./route/consumeMaterial.js";
import returnMat from "./route/returnMaterial.js";
import createSiloAdjustment from "./route/siloAdjustments/createSiloAdjustment.js";
import postComment from "./route/siloAdjustments/postComment.js";
const app = new OpenAPIHono();
const routes = [comsumeMaterial, returnMat] as const;
const routes = [
comsumeMaterial,
returnMat,
// silo
createSiloAdjustment,
postComment,
] as const;
// app.route("/server", modules);
const appRoutes = routes.forEach((route) => {

View File

@@ -0,0 +1,73 @@
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
import { modules } from "../../../../../database/schema/modules.js";
import { db } from "../../../../../database/dbclient.js";
import { subModules } from "../../../../../database/schema/subModules.js";
// 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 submodules in the server",
method: "get",
path: "/submodules",
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(subModules); // .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: m?.roles };
}
return m;
}); //JSON.parse(module[0]?.roles);
// Return response with the received data
return c.json({
message: `All active submodules`,
data: module,
});
}
);
export default app;

View File

@@ -15,6 +15,7 @@ import updateServer from "./route/updates/updateServer.js";
import { setPerms } from "./utils/testServerPerms.js";
import serviceControl from "./route/servers/serverContorl.js";
import { areSubModulesIn } from "./utils/subModuleCheck.js";
import getSubmodules from "./route/modules/getSubModules.js";
// making sure all modules are in properly
setTimeout(async () => {
@@ -31,6 +32,7 @@ const routes = [
getModules,
updateModule,
addModule,
getSubmodules,
// settings
addSetting,
getSettings,

View File

@@ -12,7 +12,7 @@ const newSubModules = [
name: "Silo Adjustmnet",
moduleName: "logistics",
description: "Do a silo adjustmnet",
link: "/sa",
link: "/siloAdjustments",
icon: "Cylinder",
active: false,
roles: ["tester", "systemAdmin"],
@@ -156,6 +156,7 @@ export const areSubModulesIn = async () => {
roles: newSubModules[i].roles,
link: newSubModules[i].link,
subSubModule: newSubModules[i].subSubModule,
icon: newSubModules[i].icon,
},
}) // this will only update the ones that are new :D
.returning({ name: subModules.name });
@@ -167,6 +168,7 @@ export const areSubModulesIn = async () => {
"SubModules were just added due to missing them on server startup"
);
} catch (error) {
console.log(error);
createLog(
"error",
"lst",