From 371c6317aa4371b879eae2acf44936c2f2c7e0b9 Mon Sep 17 00:00:00 2001 From: yni9ht Date: Mon, 17 Mar 2025 20:44:13 +0800 Subject: [PATCH 1/3] refactor(mount): streamline mount update logic and improve readability --- packages/server/src/services/mount.ts | 40 +++++++++++++-------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/packages/server/src/services/mount.ts b/packages/server/src/services/mount.ts index 836feacec..1fa4db1e5 100644 --- a/packages/server/src/services/mount.ts +++ b/packages/server/src/services/mount.ts @@ -123,29 +123,27 @@ export const updateMount = async ( mountId: string, mountData: Partial, ) => { - return await db.transaction(async (tx) => { - const mount = await tx - .update(mounts) - .set({ - ...mountData, - }) - .where(eq(mounts.mountId, mountId)) - .returning() - .then((value) => value[0]); + const mount = await db + .update(mounts) + .set({ + ...mountData, + }) + .where(eq(mounts.mountId, mountId)) + .returning() + .then((value) => value[0]); - if (!mount) { - throw new TRPCError({ - code: "NOT_FOUND", - message: "Mount not found", - }); - } + if (!mount) { + throw new TRPCError({ + code: "NOT_FOUND", + message: "Mount not found", + }); + } - if (mount.type === "file") { - await deleteFileMount(mountId); - await createFileMount(mountId); - } - return mount; - }); + if (mount.type === "file") { + await deleteFileMount(mountId); + await createFileMount(mountId); + } + return mount; }; export const findMountsByApplicationId = async ( From 5611dcccfddc47eb6f605cb2f4caae0d8db2a6c6 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sat, 26 Apr 2025 16:44:40 -0600 Subject: [PATCH 2/3] refactor(mount): enhance updateMount function with transaction handling and improved error management --- apps/dokploy/server/api/routers/mount.ts | 3 +- packages/server/src/services/mount.ts | 41 +++++++++++++----------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/apps/dokploy/server/api/routers/mount.ts b/apps/dokploy/server/api/routers/mount.ts index 0cfb0c071..9a189f614 100644 --- a/apps/dokploy/server/api/routers/mount.ts +++ b/apps/dokploy/server/api/routers/mount.ts @@ -31,7 +31,6 @@ export const mountRouter = createTRPCRouter({ update: protectedProcedure .input(apiUpdateMount) .mutation(async ({ input }) => { - await updateMount(input.mountId, input); - return true; + return await updateMount(input.mountId, input); }), }); diff --git a/packages/server/src/services/mount.ts b/packages/server/src/services/mount.ts index 1fa4db1e5..aca0db055 100644 --- a/packages/server/src/services/mount.ts +++ b/packages/server/src/services/mount.ts @@ -123,27 +123,30 @@ export const updateMount = async ( mountId: string, mountData: Partial, ) => { - const mount = await db - .update(mounts) - .set({ - ...mountData, - }) - .where(eq(mounts.mountId, mountId)) - .returning() - .then((value) => value[0]); + return await db.transaction(async (tx) => { + const mount = await tx + .update(mounts) + .set({ + ...mountData, + }) + .where(eq(mounts.mountId, mountId)) + .returning() + .then((value) => value[0]); - if (!mount) { - throw new TRPCError({ - code: "NOT_FOUND", - message: "Mount not found", - }); - } + if (!mount) { + throw new TRPCError({ + code: "NOT_FOUND", + message: "Mount not found", + }); + } - if (mount.type === "file") { - await deleteFileMount(mountId); - await createFileMount(mountId); - } - return mount; + if (mount.type === "file") { + await deleteFileMount(mountId); + await createFileMount(mountId); + } + + return await findMountById(mountId); + }); }; export const findMountsByApplicationId = async ( From a6880fd38cf358b62ba578415998dea654084508 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sat, 26 Apr 2025 22:45:14 +0000 Subject: [PATCH 3/3] [autofix.ci] apply automated fixes --- .../dashboard/compose/general/compose-file-editor.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/dokploy/components/dashboard/compose/general/compose-file-editor.tsx b/apps/dokploy/components/dashboard/compose/general/compose-file-editor.tsx index e582d266d..50f0f4ab5 100644 --- a/apps/dokploy/components/dashboard/compose/general/compose-file-editor.tsx +++ b/apps/dokploy/components/dashboard/compose/general/compose-file-editor.tsx @@ -83,15 +83,15 @@ export const ComposeFileEditor = ({ composeId }: Props) => { // Add keyboard shortcut for Ctrl+S/Cmd+S useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { - if ((e.ctrlKey || e.metaKey) && e.key === 's' && !isLoading) { + if ((e.ctrlKey || e.metaKey) && e.key === "s" && !isLoading) { e.preventDefault(); form.handleSubmit(onSubmit)(); } }; - document.addEventListener('keydown', handleKeyDown); + document.addEventListener("keydown", handleKeyDown); return () => { - document.removeEventListener('keydown', handleKeyDown); + document.removeEventListener("keydown", handleKeyDown); }; }, [form, onSubmit, isLoading]);