import {eq} from "drizzle-orm";
import {db} from "../../../../../database/dbclient.js";
import {modules} from "../../../../../database/schema/modules.js";
import {createLog} from "../../../logger/logger.js";

export const addModule = async (data: any, user_id: string) => {
    createLog("info", "lst", "server", "Module being added");
    let module;

    try {
        module = await db.insert(modules).values(data).returning({name: modules.name});
        //.where(sql`${userRole} = ANY(roles)`);
    } catch (error) {
        createLog("error", "lst", "server", "There was an error adding the module");
        throw new Error("There was an error adding the module");
    }
    return module;
};
