refactor: stash

This commit is contained in:
Mauricio Siu
2024-10-02 21:55:54 -06:00
parent ffd19f591d
commit d256998677
32 changed files with 4023 additions and 293 deletions

View File

@@ -6,14 +6,10 @@ import {
type apiUpdateSshKey,
sshKeys,
} from "@/server/db/schema";
import { removeSSHKey, saveSSHKey } from "@/server/utils/filesystem/ssh";
import { TRPCError } from "@trpc/server";
import { eq } from "drizzle-orm";
export const createSshKey = async ({
privateKey,
...input
}: typeof apiCreateSshKey._type) => {
export const createSshKey = async (input: typeof apiCreateSshKey._type) => {
await db.transaction(async (tx) => {
const sshKey = await tx
.insert(sshKeys)
@@ -22,10 +18,6 @@ export const createSshKey = async ({
.then((response) => response[0])
.catch((e) => console.error(e));
if (sshKey) {
saveSSHKey(sshKey.sshKeyId, sshKey.publicKey, privateKey);
}
if (!sshKey) {
throw new TRPCError({
code: "BAD_REQUEST",
@@ -44,8 +36,6 @@ export const removeSSHKeyById = async (
.where(eq(sshKeys.sshKeyId, sshKeyId))
.returning();
removeSSHKey(sshKeyId);
return result[0];
};