mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-17 09:25:20 +00: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,
|
pgTable,
|
||||||
text,
|
text,
|
||||||
} from "drizzle-orm/pg-core";
|
} from "drizzle-orm/pg-core";
|
||||||
|
import { createInsertSchema } from "drizzle-zod";
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { organization } from "./account";
|
import { organization } from "./account";
|
||||||
@@ -128,59 +129,77 @@ export const serverRelations = relations(server, ({ one, many }) => ({
|
|||||||
schedules: many(schedules),
|
schedules: many(schedules),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const apiCreateServer = z.object({
|
const createSchema = createInsertSchema(server, {
|
||||||
|
serverId: z.string().min(1),
|
||||||
name: z.string().min(1),
|
name: z.string().min(1),
|
||||||
description: z.string().optional(),
|
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({
|
export const apiFindOneServer = z.object({
|
||||||
serverId: z.string().min(1),
|
serverId: z.string().min(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const apiRemoveServer = z.object({
|
export const apiRemoveServer = createSchema
|
||||||
serverId: z.string().min(1),
|
.pick({
|
||||||
});
|
serverId: true,
|
||||||
|
})
|
||||||
|
.required();
|
||||||
|
|
||||||
export const apiUpdateServer = z.object({
|
export const apiUpdateServer = createSchema
|
||||||
serverId: z.string().min(1),
|
.pick({
|
||||||
name: z.string().min(1).optional(),
|
name: true,
|
||||||
description: z.string().optional(),
|
description: true,
|
||||||
ipAddress: z.string().min(1).optional(),
|
serverId: true,
|
||||||
port: z.number().optional(),
|
ipAddress: true,
|
||||||
username: z.string().min(1).optional(),
|
port: true,
|
||||||
sshKeyId: z.string().optional(),
|
username: true,
|
||||||
serverType: z.enum(["deploy", "build"]).optional(),
|
sshKeyId: true,
|
||||||
command: z.string().optional(),
|
serverType: true,
|
||||||
});
|
})
|
||||||
|
.required()
|
||||||
|
.extend({
|
||||||
|
command: z.string().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
const metricsConfigSchema = z.object({
|
export const apiUpdateServerMonitoring = createSchema
|
||||||
server: z.object({
|
.pick({
|
||||||
refreshRate: z.number().min(2),
|
serverId: true,
|
||||||
port: z.number().min(1),
|
})
|
||||||
token: z.string(),
|
.required()
|
||||||
urlCallback: z.string().url(),
|
.extend({
|
||||||
retentionDays: z.number().min(1),
|
metricsConfig: z
|
||||||
cronJob: z.string().min(1),
|
.object({
|
||||||
thresholds: z.object({
|
server: z.object({
|
||||||
cpu: z.number().min(0),
|
refreshRate: z.number().min(2),
|
||||||
memory: z.number().min(0),
|
port: z.number().min(1),
|
||||||
}),
|
token: z.string(),
|
||||||
}),
|
urlCallback: z.string().url(),
|
||||||
containers: z.object({
|
retentionDays: z.number().min(1),
|
||||||
refreshRate: z.number().min(2),
|
cronJob: z.string().min(1),
|
||||||
services: z.object({
|
thresholds: z.object({
|
||||||
include: z.array(z.string()).optional(),
|
cpu: z.number().min(0),
|
||||||
exclude: z.array(z.string()).optional(),
|
memory: z.number().min(0),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
});
|
containers: z.object({
|
||||||
|
refreshRate: z.number().min(2),
|
||||||
export const apiUpdateServerMonitoring = z.object({
|
services: z.object({
|
||||||
serverId: z.string().min(1),
|
include: z.array(z.string()).optional(),
|
||||||
metricsConfig: metricsConfigSchema,
|
exclude: z.array(z.string()).optional(),
|
||||||
});
|
}),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.required(),
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user