mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-17 17:35:17 +00:00
fix(schedule): give scheduleType a clean enum type for the host-access gate
createInsertSchema inferred scheduleType as a broadened union (drizzle-zod 0.5.1), so passing input.scheduleType into assertHostScheduleAccess failed typecheck on a cold build. Refine the insert schema's scheduleType to a plain z.enum and type the helper param as the schedule enum.
This commit is contained in:
@@ -57,6 +57,7 @@ export const schedules = pgTable("schedule", {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export type Schedule = typeof schedules.$inferSelect;
|
export type Schedule = typeof schedules.$inferSelect;
|
||||||
|
export type ScheduleType = Schedule["scheduleType"];
|
||||||
|
|
||||||
export const schedulesRelations = relations(schedules, ({ one, many }) => ({
|
export const schedulesRelations = relations(schedules, ({ one, many }) => ({
|
||||||
application: one(applications, {
|
application: one(applications, {
|
||||||
@@ -78,7 +79,14 @@ export const schedulesRelations = relations(schedules, ({ one, many }) => ({
|
|||||||
deployments: many(deployments),
|
deployments: many(deployments),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const createScheduleSchema = createInsertSchema(schedules);
|
export const createScheduleSchema = createInsertSchema(schedules, {
|
||||||
|
scheduleType: z.enum([
|
||||||
|
"application",
|
||||||
|
"compose",
|
||||||
|
"server",
|
||||||
|
"dokploy-server",
|
||||||
|
]),
|
||||||
|
});
|
||||||
|
|
||||||
export const updateScheduleSchema = createScheduleSchema.extend({
|
export const updateScheduleSchema = createScheduleSchema.extend({
|
||||||
scheduleId: z.string().min(1),
|
scheduleId: z.string().min(1),
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export type ScheduleExtended = Awaited<ReturnType<typeof findScheduleById>>;
|
|||||||
// not downgrade this to a service-access check.
|
// not downgrade this to a service-access check.
|
||||||
export const assertHostScheduleAccess = async (
|
export const assertHostScheduleAccess = async (
|
||||||
ctx: { user: { id: string }; session: { activeOrganizationId: string } },
|
ctx: { user: { id: string }; session: { activeOrganizationId: string } },
|
||||||
scheduleType: string | undefined,
|
scheduleType: Schedule["scheduleType"] | null | undefined,
|
||||||
serverId: string | null | undefined,
|
serverId: string | null | undefined,
|
||||||
) => {
|
) => {
|
||||||
if (scheduleType !== "server" && scheduleType !== "dokploy-server") return;
|
if (scheduleType !== "server" && scheduleType !== "dokploy-server") return;
|
||||||
|
|||||||
Reference in New Issue
Block a user