mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-29 11:05:33 +02:00
feat: add test connection github
This commit is contained in:
@@ -3,35 +3,7 @@ import { type apiCreateGithub, github, gitProvider } from "@/server/db/schema";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
export const createGithub = async (input: typeof apiCreateGithub._type) => {
|
||||
return await db.transaction(async (tx) => {
|
||||
const newGitProvider = await tx
|
||||
.insert(gitProvider)
|
||||
.values({
|
||||
providerType: "github",
|
||||
authId: input.authId,
|
||||
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 type GitProvider = typeof gitProvider.$inferSelect;
|
||||
|
||||
export const removeGitProvider = async (gitProviderId: string) => {
|
||||
const result = await db
|
||||
@@ -41,3 +13,17 @@ export const removeGitProvider = async (gitProviderId: string) => {
|
||||
|
||||
return result[0];
|
||||
};
|
||||
|
||||
export const updateGitProvider = async (
|
||||
gitProviderId: string,
|
||||
input: Partial<GitProvider>,
|
||||
) => {
|
||||
return await db
|
||||
.update(gitProvider)
|
||||
.set({
|
||||
...input,
|
||||
})
|
||||
.where(eq(gitProvider.gitProviderId, gitProviderId))
|
||||
.returning()
|
||||
.then((response) => response[0]);
|
||||
};
|
||||
|
||||
@@ -37,6 +37,9 @@ export const createGithub = async (input: typeof apiCreateGithub._type) => {
|
||||
export const findGithubById = async (githubId: string) => {
|
||||
const githubProviderResult = await db.query.github.findFirst({
|
||||
where: eq(github.githubId, githubId),
|
||||
with: {
|
||||
gitProvider: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!githubProviderResult) {
|
||||
@@ -56,3 +59,17 @@ export const haveGithubRequirements = (github: Github) => {
|
||||
github?.githubInstallationId
|
||||
);
|
||||
};
|
||||
|
||||
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]);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user