From d0b7ce3a50c997fdcf075a5f74c3bedd108ad11f Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Tue, 8 Jul 2025 21:52:50 -0600 Subject: [PATCH] refactor: rename findAdmin to findOwner across multiple files - Updated the function name from findAdmin to findOwner in reset-2fa.ts, reset-password.ts, user.ts, admin.ts, and access-log handler.ts to reflect the change in role terminology. - Adjusted related logic to ensure consistency in user role handling. --- apps/dokploy/reset-2fa.ts | 4 ++-- apps/dokploy/reset-password.ts | 4 ++-- apps/dokploy/server/api/routers/user.ts | 6 +++--- packages/server/src/services/admin.ts | 18 +++++++++--------- .../server/src/utils/access-log/handler.ts | 18 +++++++++--------- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/apps/dokploy/reset-2fa.ts b/apps/dokploy/reset-2fa.ts index 089b7118b..8cdea5a01 100644 --- a/apps/dokploy/reset-2fa.ts +++ b/apps/dokploy/reset-2fa.ts @@ -1,11 +1,11 @@ -import { findAdmin } from "@dokploy/server"; +import { findOwner } from "@dokploy/server"; import { db } from "@dokploy/server/db"; import { users_temp } from "@dokploy/server/db/schema"; import { eq } from "drizzle-orm"; (async () => { try { - const result = await findAdmin(); + const result = await findOwner(); const update = await db .update(users_temp) diff --git a/apps/dokploy/reset-password.ts b/apps/dokploy/reset-password.ts index 32cab4334..472fa359c 100644 --- a/apps/dokploy/reset-password.ts +++ b/apps/dokploy/reset-password.ts @@ -1,4 +1,4 @@ -import { findAdmin } from "@dokploy/server"; +import { findOwner } from "@dokploy/server"; import { generateRandomPassword } from "@dokploy/server"; import { db } from "@dokploy/server/db"; import { account } from "@dokploy/server/db/schema"; @@ -8,7 +8,7 @@ import { eq } from "drizzle-orm"; try { const randomPassword = await generateRandomPassword(); - const result = await findAdmin(); + const result = await findOwner(); const update = await db .update(account) diff --git a/apps/dokploy/server/api/routers/user.ts b/apps/dokploy/server/api/routers/user.ts index 3ac91dc03..dd0fbc1f1 100644 --- a/apps/dokploy/server/api/routers/user.ts +++ b/apps/dokploy/server/api/routers/user.ts @@ -1,7 +1,7 @@ import { IS_CLOUD, createApiKey, - findAdmin, + findOwner, findNotificationById, findOrganizationById, findUserById, @@ -410,11 +410,11 @@ export const userRouter = createTRPCRouter({ }); } - const admin = await findAdmin(); + const owner = await findOwner(); const host = process.env.NODE_ENV === "development" ? "http://localhost:3000" - : admin.user.host; + : owner.user.host; const inviteLink = `${host}/invitation?token=${input.invitationId}`; const organization = await findOrganizationById( diff --git a/packages/server/src/services/admin.ts b/packages/server/src/services/admin.ts index f6ce9614f..c709936b5 100644 --- a/packages/server/src/services/admin.ts +++ b/packages/server/src/services/admin.ts @@ -46,21 +46,21 @@ export const isAdminPresent = async () => { return true; }; -export const findAdmin = async () => { - const admin = await db.query.member.findFirst({ +export const findOwner = async () => { + const owner = await db.query.member.findFirst({ where: eq(member.role, "owner"), with: { user: true, }, }); - if (!admin) { + if (!owner) { throw new TRPCError({ code: "NOT_FOUND", - message: "Admin not found", + message: "Owner not found", }); } - return admin; + return owner; }; export const getUserByToken = async (token: string) => { @@ -107,10 +107,10 @@ export const getDokployUrl = async () => { if (IS_CLOUD) { return "https://app.dokploy.com"; } - const admin = await findAdmin(); + const owner = await findOwner(); - if (admin.user.host) { - return `https://${admin.user.host}`; + if (owner.user.host) { + return `https://${owner.user.host}`; } - return `http://${admin.user.serverIp}:${process.env.PORT}`; + return `http://${owner.user.serverIp}:${process.env.PORT}`; }; diff --git a/packages/server/src/utils/access-log/handler.ts b/packages/server/src/utils/access-log/handler.ts index bc2356935..7a960bd78 100644 --- a/packages/server/src/utils/access-log/handler.ts +++ b/packages/server/src/utils/access-log/handler.ts @@ -1,5 +1,5 @@ import { paths } from "@dokploy/server/constants"; -import { findAdmin } from "@dokploy/server/services/admin"; +import { findOwner } from "@dokploy/server/services/admin"; import { updateUser } from "@dokploy/server/services/user"; import { scheduleJob, scheduledJobs } from "node-schedule"; import { execAsync } from "../process/execAsync"; @@ -29,9 +29,9 @@ export const startLogCleanup = async ( } }); - const admin = await findAdmin(); - if (admin) { - await updateUser(admin.user.id, { + const owner = await findOwner(); + if (owner) { + await updateUser(owner.user.id, { logCleanupCron: cronExpression, }); } @@ -51,9 +51,9 @@ export const stopLogCleanup = async (): Promise => { } // Update database - const admin = await findAdmin(); - if (admin) { - await updateUser(admin.user.id, { + const owner = await findOwner(); + if (owner) { + await updateUser(owner.user.id, { logCleanupCron: null, }); } @@ -69,8 +69,8 @@ export const getLogCleanupStatus = async (): Promise<{ enabled: boolean; cronExpression: string | null; }> => { - const admin = await findAdmin(); - const cronExpression = admin?.user.logCleanupCron ?? null; + const owner = await findOwner(); + const cronExpression = owner?.user.logCleanupCron ?? null; return { enabled: cronExpression !== null, cronExpression,