Mauricio Siurefactor: update43099392 years agoHistory
74 lines · 1.5 KB · TypeScript
RawDownload
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]);};