mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: update gitlab update name
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { createGithub } from "@/server/api/services/git-provider";
|
import { createGithub } from "@/server/api/services/github";
|
||||||
import { db } from "@/server/db";
|
import { db } from "@/server/db";
|
||||||
import { github } from "@/server/db/schema";
|
import { github } from "@/server/db/schema";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import {
|
import { findGitlabById, updateGitlab } from "@/server/api/services/gitlab";
|
||||||
findGitlabById,
|
|
||||||
updateGitlab,
|
|
||||||
} from "@/server/api/services/git-provider";
|
|
||||||
import type { NextApiRequest, NextApiResponse } from "next";
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
|
||||||
export default async function handler(
|
export default async function handler(
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import { createGitlab, findGitlabById, updateGitlab } from "../services/gitlab";
|
import { createGitlab, findGitlabById, updateGitlab } from "../services/gitlab";
|
||||||
import { db } from "@/server/db";
|
import { db } from "@/server/db";
|
||||||
|
import { updateGitProvider } from "../services/git-provider";
|
||||||
|
|
||||||
export const gitlabRouter = createTRPCRouter({
|
export const gitlabRouter = createTRPCRouter({
|
||||||
create: protectedProcedure
|
create: protectedProcedure
|
||||||
@@ -81,6 +82,12 @@ export const gitlabRouter = createTRPCRouter({
|
|||||||
update: protectedProcedure
|
update: protectedProcedure
|
||||||
.input(apiUpdateGitlab)
|
.input(apiUpdateGitlab)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input }) => {
|
||||||
return await updateGitlab(input.gitlabId, input);
|
if (input.name) {
|
||||||
|
await updateGitProvider(input.gitProviderId, {
|
||||||
|
name: input.name,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await updateGitlab(input.gitlabId, input);
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { db } from "@/server/db";
|
import { db } from "@/server/db";
|
||||||
import {
|
import {
|
||||||
type apiCreateGitlab,
|
type apiCreateGitlab,
|
||||||
type apiUpdateGitlab,
|
|
||||||
type bitbucket,
|
type bitbucket,
|
||||||
type github,
|
type github,
|
||||||
gitlab,
|
gitlab,
|
||||||
@@ -63,33 +62,6 @@ export const findGitlabById = async (gitlabId: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const updateGitlab = async (
|
export const updateGitlab = async (
|
||||||
gitlabId: string,
|
|
||||||
input: typeof apiUpdateGitlab._type,
|
|
||||||
) => {
|
|
||||||
return await db.transaction(async (tx) => {
|
|
||||||
const result = await tx
|
|
||||||
.update(gitlab)
|
|
||||||
.set({
|
|
||||||
...input,
|
|
||||||
})
|
|
||||||
.where(eq(gitlab.gitlabId, gitlabId))
|
|
||||||
.returning();
|
|
||||||
|
|
||||||
if (input.name) {
|
|
||||||
await tx
|
|
||||||
.update(gitProvider)
|
|
||||||
.set({
|
|
||||||
name: input.name,
|
|
||||||
})
|
|
||||||
.where(eq(gitProvider.gitProviderId, input.gitProviderId))
|
|
||||||
.returning();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result[0];
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const updateGitlabComplete = async (
|
|
||||||
gitlabId: string,
|
gitlabId: string,
|
||||||
input: Partial<Gitlab>,
|
input: Partial<Gitlab>,
|
||||||
) => {
|
) => {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import type { InferResultType } from "@/server/types/with";
|
|||||||
import type { Compose } from "@/server/api/services/compose";
|
import type { Compose } from "@/server/api/services/compose";
|
||||||
import {
|
import {
|
||||||
findGitlabById,
|
findGitlabById,
|
||||||
updateGitlabComplete,
|
updateGitlab,
|
||||||
type Gitlab,
|
type Gitlab,
|
||||||
} from "@/server/api/services/gitlab";
|
} from "@/server/api/services/gitlab";
|
||||||
import type { apiGitlabTestConnection } from "@/server/db/schema";
|
import type { apiGitlabTestConnection } from "@/server/db/schema";
|
||||||
@@ -48,7 +48,7 @@ export const refreshGitlabToken = async (gitlabProviderId: string) => {
|
|||||||
|
|
||||||
console.log("Refreshed token");
|
console.log("Refreshed token");
|
||||||
|
|
||||||
await updateGitlabComplete(gitlabProviderId, {
|
await updateGitlab(gitlabProviderId, {
|
||||||
accessToken: data.access_token,
|
accessToken: data.access_token,
|
||||||
refreshToken: data.refresh_token,
|
refreshToken: data.refresh_token,
|
||||||
expiresAt,
|
expiresAt,
|
||||||
|
|||||||
Reference in New Issue
Block a user