feat(server): added in a default set of settings that will be checked on startup

This commit is contained in:
2025-03-06 19:33:36 -06:00
parent 71a951a9f2
commit 4195b9e8bc
17 changed files with 3478 additions and 6 deletions

View File

@@ -20,10 +20,10 @@ export const addSetting = async (data: any, user_id: string) => {
const moduleId = await db.select().from(modules).where(eq(modules.name, data.module));
// filter out the module and add in the module id
delete data.module;
//delete data.module;
data.module_id = moduleId[0].module_id;
console.log(data);
//data.moduleName = moduleId[0].module_id;
// console.log(data);
const createSetting = await db.insert(settings).values(data);
} catch (error) {
log.error(error, "Error adding setting");

View File

@@ -8,7 +8,10 @@ import addModule from "./route/modules/addModule.js";
import addSetting from "./route/settings/addSetting.js";
import getSettings from "./route/settings/getSettings.js";
import updateSetting from "./route/settings/updateSetting.js";
import {areSettingsIn} from "./utils/settingsCheck.js";
// making sure all modules are in properly
areSettingsIn();
areModulesIn();
const app = new OpenAPIHono();

View File

@@ -0,0 +1,80 @@
/**
* check if the modules are in and if not add them.
* this will only run on a server start up
*/
import {db} from "../../../../database/dbclient.js";
import {settings} from "../../../../database/schema/settings.js";
import {log} from "../../logger/logger.js";
// "view", "technician", "supervisor","manager", "admin", "systemAdmin"
const newSettings = [
{name: "server", value: "localhost", description: "Where the app runs at", moduleName: "server"},
{name: "serverPort", value: "4400", description: "What are we listening on", moduleName: "server"},
{name: "dbUser", value: "alplaprod", description: "What is the db username", moduleName: "server"},
{name: "dbPass", value: "b2JlbGl4", description: "What is the db password", moduleName: "server"},
{
name: "tcpPort",
value: "2222",
description: "TCP port for printers to connect send data and the zedra cameras",
moduleName: "server",
},
{
name: "prolinkCheck",
value: "1",
description:
"Will prolink be considered to check if matches, maninly used in plants that do not fully utilize prolink + ocp",
moduleName: "production",
},
{
name: "bookin",
value: "1",
description: "do we want to book in after a label is printed",
moduleName: "ocp",
},
{
name: "dbServer",
value: "usmcd1vms036",
description: "What server is the prod db on?",
moduleName: "server",
},
{
name: "printDelay",
value: "90",
description: "How long in seconds between prints",
moduleName: "ocp",
},
{
name: "plantToken",
value: "test3",
description: "What is the plant token",
moduleName: "server",
},
{
name: "dualPrinting",
value: "0",
description: "Dose the plant have 2 machines that go to 1?",
moduleName: "ocp",
},
];
export const areSettingsIn = async () => {
// get the roles
try {
const settingsCheck = await db.select().from(settings);
if (settingsCheck.length !== newSettings.length) {
try {
const newRole = await db
.insert(settings)
.values(newSettings)
.onConflictDoNothing() // this will only update the ones that are new :D
.returning({name: settings.name});
log.info(newRole, "Roles were just added due to missing them on server startup");
} catch (error) {
log.error(error, "There was an error adding new roles to the db");
}
}
} catch (error) {
log.error(error, "There was an error getting or adding new roles");
}
};