feat: add test connection github

This commit is contained in:
Mauricio Siu
2024-09-01 22:00:10 -06:00
parent 99f63597a8
commit 68d2e73e7a
6 changed files with 225 additions and 32 deletions

View File

@@ -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]);
};

View File

@@ -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]);
};