mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: migration
This commit is contained in:
46
apps/mig/server/api/routers/git-provider.ts
Normal file
46
apps/mig/server/api/routers/git-provider.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { createTRPCRouter, protectedProcedure } from "@/server/api/trpc";
|
||||
import { db } from "@/server/db";
|
||||
import { apiRemoveGitProvider, gitProvider } from "@/server/db/schema";
|
||||
import {
|
||||
IS_CLOUD,
|
||||
findGitProviderById,
|
||||
removeGitProvider,
|
||||
} from "@dokploy/server";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { 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,
|
||||
},
|
||||
orderBy: desc(gitProvider.createdAt),
|
||||
...(IS_CLOUD && { where: eq(gitProvider.adminId, ctx.user.adminId) }),
|
||||
//TODO: Remove this line when the cloud version is ready
|
||||
});
|
||||
}),
|
||||
remove: protectedProcedure
|
||||
.input(apiRemoveGitProvider)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
try {
|
||||
const gitProvider = await findGitProviderById(input.gitProviderId);
|
||||
|
||||
if (IS_CLOUD && gitProvider.adminId !== ctx.user.adminId) {
|
||||
// TODO: Remove isCloud in the next versions of dokploy
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
message: "You are not allowed to delete this git provider",
|
||||
});
|
||||
}
|
||||
return await removeGitProvider(input.gitProviderId);
|
||||
} catch (error) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Error to delete this git provider",
|
||||
});
|
||||
}
|
||||
}),
|
||||
});
|
||||
Reference in New Issue
Block a user