refactor(mount): enhance updateMount function with transaction handling and improved error management

This commit is contained in:
Mauricio Siu
2025-04-26 16:44:40 -06:00
parent 371c6317aa
commit 5611dcccfd
2 changed files with 23 additions and 21 deletions

View File

@@ -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;
}), }),
}); });

View File

@@ -123,7 +123,8 @@ export const updateMount = async (
mountId: string, mountId: string,
mountData: Partial<Mount>, mountData: Partial<Mount>,
) => { ) => {
const mount = await db return await db.transaction(async (tx) => {
const mount = await tx
.update(mounts) .update(mounts)
.set({ .set({
...mountData, ...mountData,
@@ -143,7 +144,9 @@ export const updateMount = async (
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 (