mirror of
https://github.com/andwati/dokploy.git
synced 2026-10-29 08:12:15 +00:00
refactor: update database imports to use centralized db module for improved consistency across API routes and schemas
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { relations } from "drizzle-orm";
|
||||
import { pgTable, text } from "drizzle-orm/pg-core";
|
||||
import { createInsertSchema } from "drizzle-zod";
|
||||
import { nanoid } from "nanoid";
|
||||
import { z } from "zod";
|
||||
import { sshKeyCreate, sshKeyType } from "../validations";
|
||||
@@ -36,13 +37,21 @@ export const sshKeysRelations = relations(sshKeys, ({ many, one }) => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
export const apiCreateSshKey = z.object({
|
||||
name: z.string().min(1),
|
||||
description: z.string().optional(),
|
||||
organizationId: z.string().min(1),
|
||||
publicKey: sshKeyCreate.shape.publicKey,
|
||||
privateKey: sshKeyCreate.shape.privateKey,
|
||||
});
|
||||
const createSchema = createInsertSchema(
|
||||
sshKeys,
|
||||
/* Private key is not stored in the DB */
|
||||
sshKeyCreate.omit({ privateKey: true }).shape,
|
||||
);
|
||||
|
||||
export const apiCreateSshKey = createSchema
|
||||
.pick({
|
||||
name: true,
|
||||
description: true,
|
||||
privateKey: true,
|
||||
publicKey: true,
|
||||
organizationId: true,
|
||||
})
|
||||
.merge(sshKeyCreate.pick({ privateKey: true }));
|
||||
|
||||
export const apiFindOneSshKey = z.object({
|
||||
sshKeyId: z.string().min(1),
|
||||
@@ -50,13 +59,23 @@ export const apiFindOneSshKey = z.object({
|
||||
|
||||
export const apiGenerateSSHKey = sshKeyType;
|
||||
|
||||
export const apiRemoveSshKey = z.object({
|
||||
sshKeyId: z.string().min(1),
|
||||
});
|
||||
export const apiRemoveSshKey = createSchema
|
||||
.pick({
|
||||
sshKeyId: true,
|
||||
})
|
||||
.required();
|
||||
|
||||
export const apiUpdateSshKey = z.object({
|
||||
sshKeyId: z.string().min(1),
|
||||
name: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
lastUsedAt: z.string().optional(),
|
||||
});
|
||||
export const apiUpdateSshKey = createSchema
|
||||
.pick({
|
||||
name: true,
|
||||
description: true,
|
||||
lastUsedAt: true,
|
||||
})
|
||||
.partial()
|
||||
.merge(
|
||||
createSchema
|
||||
.pick({
|
||||
sshKeyId: true,
|
||||
})
|
||||
.required(),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user