feat(server): settings and module crud added in

This commit is contained in:
2025-03-04 16:43:45 -06:00
parent 5b9cadb76e
commit 2ad1dcc55b
19 changed files with 701 additions and 14 deletions

View File

@@ -0,0 +1,18 @@
import {eq} from "drizzle-orm";
import {db} from "../../../../../database/dbclient.js";
import {modules} from "../../../../../database/schema/modules.js";
import {log} from "../../../logger/logger.js";
export const addModule = async (data: any, user_id: string) => {
log.info("Module being added");
let module;
try {
module = await db.insert(modules).values(data).returning({name: modules.name});
//.where(sql`${userRole} = ANY(roles)`);
} catch (error) {
log.error(error, "There was an error adding the module");
throw new Error("There was an error adding the module");
}
return module;
};

View File

@@ -0,0 +1,22 @@
import {eq} from "drizzle-orm";
import {db} from "../../../../../database/dbclient.js";
import {modules} from "../../../../../database/schema/modules.js";
import {log} from "../../../logger/logger.js";
export const updateModule = async (data: any, moduleID: string) => {
log.info("Module being updated");
let module;
try {
module = await db
.update(modules)
.set({active: data?.active})
.where(eq(modules.module_id, moduleID))
.returning({name: modules.name});
//.where(sql`${userRole} = ANY(roles)`);
} catch (error) {
log.error(error, "There was an error updating the module");
throw new Error("There was an error updating the module");
}
return module;
};