mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { createTRPCRouter, protectedProcedure } from "@/server/api/trpc";
|
|
import { db } from "@/server/db";
|
|
import { apiRemoveGitProvider, gitProvider } from "@/server/db/schema";
|
|
import { findGitProviderById, removeGitProvider } from "@dokploy/server";
|
|
import { TRPCError } from "@trpc/server";
|
|
import { and, desc, eq } from "drizzle-orm";
|
|
|
|
export const gitProviderRouter = createTRPCRouter({
|
|
getAll: protectedProcedure.query(async ({ ctx }) => {
|
|
return await db.query.gitProvider.findMany({
|
|
with: {
|
|
gitlab: true,
|
|
bitbucket: true,
|
|
github: true,
|
|
gitea: true,
|
|
},
|
|
orderBy: desc(gitProvider.createdAt),
|
|
where: and(
|
|
eq(gitProvider.userId, ctx.session.userId),
|
|
eq(gitProvider.organizationId, ctx.session.activeOrganizationId),
|
|
),
|
|
});
|
|
}),
|
|
remove: protectedProcedure
|
|
.input(apiRemoveGitProvider)
|
|
.mutation(async ({ input, ctx }) => {
|
|
try {
|
|
const gitProvider = await findGitProviderById(input.gitProviderId);
|
|
|
|
if (gitProvider.organizationId !== ctx.session.activeOrganizationId) {
|
|
throw new TRPCError({
|
|
code: "UNAUTHORIZED",
|
|
message: "You are not allowed to delete this Git provider",
|
|
});
|
|
}
|
|
return await removeGitProvider(input.gitProviderId);
|
|
} catch (error) {
|
|
const message =
|
|
error instanceof Error
|
|
? error.message
|
|
: "Error deleting this Git provider";
|
|
throw new TRPCError({
|
|
code: "BAD_REQUEST",
|
|
message,
|
|
});
|
|
}
|
|
}),
|
|
});
|