mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-15 20:25:23 +02:00
refactor: utilize createInsertSchema for server API schemas to enhance consistency and clarity across create, update, and remove operations
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
pgTable,
|
||||
text,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { createInsertSchema } from "drizzle-zod";
|
||||
import { nanoid } from "nanoid";
|
||||
import { z } from "zod";
|
||||
import { organization } from "./account";
|
||||
@@ -128,59 +129,77 @@ export const serverRelations = relations(server, ({ one, many }) => ({
|
||||
schedules: many(schedules),
|
||||
}));
|
||||
|
||||
export const apiCreateServer = z.object({
|
||||
const createSchema = createInsertSchema(server, {
|
||||
serverId: z.string().min(1),
|
||||
name: z.string().min(1),
|
||||
description: z.string().optional(),
|
||||
ipAddress: z.string().min(1),
|
||||
port: z.number(),
|
||||
username: z.string().min(1),
|
||||
sshKeyId: z.string().optional(),
|
||||
serverType: z.enum(["deploy", "build"]).optional(),
|
||||
});
|
||||
|
||||
export const apiCreateServer = createSchema
|
||||
.pick({
|
||||
name: true,
|
||||
description: true,
|
||||
ipAddress: true,
|
||||
port: true,
|
||||
username: true,
|
||||
sshKeyId: true,
|
||||
serverType: true,
|
||||
})
|
||||
.required();
|
||||
|
||||
export const apiFindOneServer = z.object({
|
||||
serverId: z.string().min(1),
|
||||
});
|
||||
|
||||
export const apiRemoveServer = z.object({
|
||||
serverId: z.string().min(1),
|
||||
});
|
||||
export const apiRemoveServer = createSchema
|
||||
.pick({
|
||||
serverId: true,
|
||||
})
|
||||
.required();
|
||||
|
||||
export const apiUpdateServer = z.object({
|
||||
serverId: z.string().min(1),
|
||||
name: z.string().min(1).optional(),
|
||||
description: z.string().optional(),
|
||||
ipAddress: z.string().min(1).optional(),
|
||||
port: z.number().optional(),
|
||||
username: z.string().min(1).optional(),
|
||||
sshKeyId: z.string().optional(),
|
||||
serverType: z.enum(["deploy", "build"]).optional(),
|
||||
command: z.string().optional(),
|
||||
});
|
||||
export const apiUpdateServer = createSchema
|
||||
.pick({
|
||||
name: true,
|
||||
description: true,
|
||||
serverId: true,
|
||||
ipAddress: true,
|
||||
port: true,
|
||||
username: true,
|
||||
sshKeyId: true,
|
||||
serverType: true,
|
||||
})
|
||||
.required()
|
||||
.extend({
|
||||
command: z.string().optional(),
|
||||
});
|
||||
|
||||
const metricsConfigSchema = z.object({
|
||||
server: z.object({
|
||||
refreshRate: z.number().min(2),
|
||||
port: z.number().min(1),
|
||||
token: z.string(),
|
||||
urlCallback: z.string().url(),
|
||||
retentionDays: z.number().min(1),
|
||||
cronJob: z.string().min(1),
|
||||
thresholds: z.object({
|
||||
cpu: z.number().min(0),
|
||||
memory: z.number().min(0),
|
||||
}),
|
||||
}),
|
||||
containers: z.object({
|
||||
refreshRate: z.number().min(2),
|
||||
services: z.object({
|
||||
include: z.array(z.string()).optional(),
|
||||
exclude: z.array(z.string()).optional(),
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
export const apiUpdateServerMonitoring = z.object({
|
||||
serverId: z.string().min(1),
|
||||
metricsConfig: metricsConfigSchema,
|
||||
});
|
||||
export const apiUpdateServerMonitoring = createSchema
|
||||
.pick({
|
||||
serverId: true,
|
||||
})
|
||||
.required()
|
||||
.extend({
|
||||
metricsConfig: z
|
||||
.object({
|
||||
server: z.object({
|
||||
refreshRate: z.number().min(2),
|
||||
port: z.number().min(1),
|
||||
token: z.string(),
|
||||
urlCallback: z.string().url(),
|
||||
retentionDays: z.number().min(1),
|
||||
cronJob: z.string().min(1),
|
||||
thresholds: z.object({
|
||||
cpu: z.number().min(0),
|
||||
memory: z.number().min(0),
|
||||
}),
|
||||
}),
|
||||
containers: z.object({
|
||||
refreshRate: z.number().min(2),
|
||||
services: z.object({
|
||||
include: z.array(z.string()).optional(),
|
||||
exclude: z.array(z.string()).optional(),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
.required(),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user