fix(modules): added in a type check to make sure a boolean is sent over
This commit is contained in:
@@ -3,14 +3,22 @@ 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) => {
|
||||
type Data = {
|
||||
active: boolean;
|
||||
};
|
||||
export const updateModule = async (data: Data, moduleID: string) => {
|
||||
log.info("Module being updated");
|
||||
let module;
|
||||
|
||||
if (typeof data.active !== "boolean") {
|
||||
log.error("Invalid data type: 'active' must be a boolean");
|
||||
throw new Error("'active' must be a boolean");
|
||||
}
|
||||
|
||||
try {
|
||||
module = await db
|
||||
.update(modules)
|
||||
.set({active: data?.active})
|
||||
.set({active: data.active})
|
||||
.where(eq(modules.module_id, moduleID))
|
||||
.returning({name: modules.name});
|
||||
//.where(sql`${userRole} = ANY(roles)`);
|
||||
|
||||
Reference in New Issue
Block a user