mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
75 lines
1.5 KiB
TypeScript
75 lines
1.5 KiB
TypeScript
import { db } from "@dokploy/server/db";
|
|
import {
|
|
type apiCreateGithub,
|
|
gitProvider,
|
|
github,
|
|
} from "@dokploy/server/db/schema";
|
|
import { TRPCError } from "@trpc/server";
|
|
import { eq } from "drizzle-orm";
|
|
|
|
export type Github = typeof github.$inferSelect;
|
|
export const createGithub = async (
|
|
input: typeof apiCreateGithub._type,
|
|
adminId: string,
|
|
) => {
|
|
return await db.transaction(async (tx) => {
|
|
const newGitProvider = await tx
|
|
.insert(gitProvider)
|
|
.values({
|
|
providerType: "github",
|
|
adminId: adminId,
|
|
name: input.name,
|
|
})
|
|
.returning()
|
|
.then((response) => response[0]);
|
|
|
|
if (!newGitProvider) {
|
|
throw new TRPCError({
|
|
code: "BAD_REQUEST",
|
|
message: "Error to create the git provider",
|
|
});
|
|
}
|
|
|
|
return await tx
|
|
.insert(github)
|
|
.values({
|
|
...input,
|
|
gitProviderId: newGitProvider?.gitProviderId,
|
|
})
|
|
.returning()
|
|
.then((response) => response[0]);
|
|
});
|
|
};
|
|
|
|
export const findGithubById = async (githubId: string) => {
|
|
const githubProviderResult = await db.query.github.findFirst({
|
|
where: eq(github.githubId, githubId),
|
|
with: {
|
|
gitProvider: true,
|
|
},
|
|
});
|
|
|
|
if (!githubProviderResult) {
|
|
throw new TRPCError({
|
|
code: "NOT_FOUND",
|
|
message: "Github Provider not found",
|
|
});
|
|
}
|
|
|
|
return githubProviderResult;
|
|
};
|
|
|
|
export const updateGithub = async (
|
|
githubId: string,
|
|
input: Partial<Github>,
|
|
) => {
|
|
return await db
|
|
.update(github)
|
|
.set({
|
|
...input,
|
|
})
|
|
.where(eq(github.githubId, githubId))
|
|
.returning()
|
|
.then((response) => response[0]);
|
|
};
|