import { db } from "../../../../../database/dbclient.js";
import { userRoles } from "../../../../../database/schema/userRoles.js";
import { returnRes } from "../../../../globalUtils/routeDefs/returnRes.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { createLog } from "../../../logger/logger.js";

export const getAllUsersRoles = async () => {
    /**
     * returns all users that are in lst
     */
    createLog("info", "apiAuthedRoute", "auth", "Get all users");
    const { data, error } = await tryCatch(db.select().from(userRoles));

    if (error) {
        return returnRes(
            false,
            "auth",
            "auth",
            "There was an error getting users",
            "error",
            new Error("No user exists.")
        );
    }

    return returnRes(true, "auth", "auth", "All users.", "info", data);
};
