refactor(settings): migrate user settings to webServerSettings schema and update related components

This commit is contained in:
Mauricio Siu
2025-12-21 01:33:18 -06:00
parent e77f276785
commit babd30a110
24 changed files with 7452 additions and 244 deletions

View File

@@ -1,8 +1,8 @@
import {
findUserById,
getWebServerSettings,
IS_CLOUD,
setupWebMonitoring,
updateUser,
updateWebServerSettings,
} from "@dokploy/server";
import { TRPCError } from "@trpc/server";
import { apiUpdateWebServerMonitoring } from "@/server/db/schema";
@@ -11,7 +11,7 @@ import { adminProcedure, createTRPCRouter } from "../trpc";
export const adminRouter = createTRPCRouter({
setupMonitoring: adminProcedure
.input(apiUpdateWebServerMonitoring)
.mutation(async ({ input, ctx }) => {
.mutation(async ({ input }) => {
try {
if (IS_CLOUD) {
throw new TRPCError({
@@ -19,15 +19,8 @@ export const adminRouter = createTRPCRouter({
message: "Feature disabled on cloud",
});
}
const user = await findUserById(ctx.user.ownerId);
if (user.id !== ctx.user.ownerId) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You are not authorized to setup the monitoring",
});
}
await updateUser(user.id, {
await updateWebServerSettings({
metricsConfig: {
server: {
type: "Dokploy",
@@ -52,8 +45,9 @@ export const adminRouter = createTRPCRouter({
},
});
const currentServer = await setupWebMonitoring(user.id);
return currentServer;
await setupWebMonitoring();
const settings = await getWebServerSettings();
return settings;
} catch (error) {
throw error;
}