/** * check if the modules are in and if not add them. * this will only run on a server start up */ import { sql } from "drizzle-orm"; import { db } from "../../../../database/dbclient.js"; import { prodPermissions } from "../../../../database/schema/prodPermissions.js"; import { createLog } from "../../logger/logger.js"; // "view", "technician", "supervisor","manager", "admin", "systemAdmin" const newProdRoles: any = [ { name: "planning", description: "Planning viewer only", roles: ["Manufacturing\\IssueMaterial\\MaterialHandler"], rolesLegacy: [3], }, { name: "prodsupervisor", description: "Production supervisor, planning, labeling, and production contorlling.", roles: [ "Manufacturing\\IssueMaterial\\MaterialHandler", "Manufacturing\\IssueMaterial\\ProcessAdmin", "Manufacturing\\ProductionLabelling\\ProcessAdmin", ], rolesLegacy: [3, 11, 41, 48, 49], }, ]; export const prodRoles = async () => { // get the roles for (let i = 0; i < newProdRoles.length; i++) { try { const newRole = await db .insert(prodPermissions) .values(newProdRoles[i]) .onConflictDoUpdate({ target: prodPermissions.name, set: { name: newProdRoles[i].name, description: newProdRoles[i].description, roles: newProdRoles[i].roles, rolesLegacy: newProdRoles[i].rolesLegacy, upd_date: sql`NOW()`, }, }) // this will only update the ones that are new :D .returning({ name: prodPermissions.name }); } catch (error) { console.log(error); createLog( "error", "lst", "server", "There was an error adding new modules to the db" ); } } createLog( "info", "lst", "server", "Modules were just added due to missing them on server startup" ); };