style(auth): format changes to the new config only

This commit is contained in:
2025-04-02 21:24:51 -05:00
parent 3355eb389c
commit b48dd8fa15
3 changed files with 90 additions and 64 deletions

View File

@@ -3,12 +3,20 @@ import {db} from "../../../../database/dbclient.js";
import { users } from "../../../../database/schema/users.js";
import { createPassword } from "../utils/createPassword.js";
import { setSysAdmin } from "./userRoles/setSysAdmin.js";
import { createLog } from "../../logger/logger.js";
export const registerUser = async (username: string, password: string, email: string) => {
export const registerUser = async (
username: string,
password: string,
email: string
) => {
const usercount = await db.select().from(users);
// make sure the user dose not already exist in the system
const userCheck = await db.select().from(users).where(eq(users.username, username));
const userCheck = await db
.select()
.from(users)
.where(eq(users.username, username));
if (userCheck.length === 1) {
return {
@@ -30,14 +38,22 @@ export const registerUser = async (username: string, password: string, email: st
.returning({ user: users.username, email: users.email });
if (usercount.length <= 1) {
console.log(`${username} is the first user and will be set to system admin.`);
const updateUser = await db.select().from(users).where(eq(users.username, username));
createLog(
"info",
"auth",
"auth",
`${username} is the first user and will be set to system admin.`
);
const updateUser = await db
.select()
.from(users)
.where(eq(users.username, username));
setSysAdmin(updateUser, "systemAdmin");
}
return { sucess: true, message: "User Registered", user };
} catch (error) {
console.log(error);
createLog("error", "auth", "auth", `${error}`);
return {
success: false,
message: `${username} already exists please login or reset password, if you feel this is an error please contact your admin.`,

View File

@@ -48,10 +48,19 @@ app.openapi(
//apiHit(c, { endpoint: "api/auth/setUserRoles" });
const { username, module, role, override } = await c.req.json();
try {
const access = await setUserAccess(username, module, role, override);
const access = await setUserAccess(
username,
module,
role,
override
);
//return apiReturn(c, true, access?.message, access?.data, 200);
return c.json(
{ success: access.success, message: access.message, data: access.data },
{
success: access.success,
message: access.message,
data: access.data,
},
200
);
} catch (error) {

View File

@@ -9,6 +9,7 @@ import { createLog } from "../logger/logger.js";
import { note, notificationCreate } from "./utils/masterNotifications.js";
import { startNotificationMonitor } from "./utils/processNotifications.js";
import notifyStats from "./routes/getActiveNotifications.js";
const app = new OpenAPIHono();
const routes = [sendemail, notifyStats] as const;