mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor(mount): enhance updateMount function with transaction handling and improved error management
This commit is contained in:
@@ -31,7 +31,6 @@ export const mountRouter = createTRPCRouter({
|
|||||||
update: protectedProcedure
|
update: protectedProcedure
|
||||||
.input(apiUpdateMount)
|
.input(apiUpdateMount)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input }) => {
|
||||||
await updateMount(input.mountId, input);
|
return await updateMount(input.mountId, input);
|
||||||
return true;
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -123,27 +123,30 @@ export const updateMount = async (
|
|||||||
mountId: string,
|
mountId: string,
|
||||||
mountData: Partial<Mount>,
|
mountData: Partial<Mount>,
|
||||||
) => {
|
) => {
|
||||||
const mount = await db
|
return await db.transaction(async (tx) => {
|
||||||
.update(mounts)
|
const mount = await tx
|
||||||
.set({
|
.update(mounts)
|
||||||
...mountData,
|
.set({
|
||||||
})
|
...mountData,
|
||||||
.where(eq(mounts.mountId, mountId))
|
})
|
||||||
.returning()
|
.where(eq(mounts.mountId, mountId))
|
||||||
.then((value) => value[0]);
|
.returning()
|
||||||
|
.then((value) => value[0]);
|
||||||
|
|
||||||
if (!mount) {
|
if (!mount) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "NOT_FOUND",
|
code: "NOT_FOUND",
|
||||||
message: "Mount not found",
|
message: "Mount not found",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mount.type === "file") {
|
if (mount.type === "file") {
|
||||||
await deleteFileMount(mountId);
|
await deleteFileMount(mountId);
|
||||||
await createFileMount(mountId);
|
await createFileMount(mountId);
|
||||||
}
|
}
|
||||||
return mount;
|
|
||||||
|
return await findMountById(mountId);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const findMountsByApplicationId = async (
|
export const findMountsByApplicationId = async (
|
||||||
|
|||||||
Reference in New Issue
Block a user