From ee884ccdf228af6b903b19df35357f4356d3b86d Mon Sep 17 00:00:00 2001 From: Michael T Date: Fri, 23 Jan 2026 15:29:16 -0500 Subject: [PATCH] fix(api): use synchronous transaction for wishlist reorder better-sqlite3 doesn't support async transactions. Removed async/await and used synchronous .run() and .all() methods instead. Fixes #38 --- app/api/wishlists/[id]/reorder/route.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/api/wishlists/[id]/reorder/route.ts b/app/api/wishlists/[id]/reorder/route.ts index fb9bd94..8ae7768 100644 --- a/app/api/wishlists/[id]/reorder/route.ts +++ b/app/api/wishlists/[id]/reorder/route.ts @@ -101,24 +101,24 @@ export async function POST( allWishlists.splice(newSortOrder, 0, movingWishlist); // Update all sortOrders in a transaction for atomicity - const updatedWishlist = await db.transaction(async (tx) => { - // Update all sortOrders + // Note: better-sqlite3 is synchronous, so no async/await in transaction + const updatedWishlist = db.transaction((tx) => { for (let i = 0; i < allWishlists.length; i++) { - await tx - .update(wishlists) + tx.update(wishlists) .set({ sortOrder: i, updatedAt: new Date(), }) - .where(eq(wishlists.id, allWishlists[i].id)); + .where(eq(wishlists.id, allWishlists[i].id)) + .run(); } - // Get the updated wishlist - const result = await tx + const result = tx .select() .from(wishlists) .where(eq(wishlists.id, id)) - .limit(1); + .limit(1) + .all(); return result[0]; });