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

@@ -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");
}
};