fix: sync reorder transaction + redirect unauthenticated users to wishlist
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled

- reorder route used async callback with better-sqlite3 (sync driver),
  causing "Transaction function cannot return a promise" — converted to sync
- home page now redirects unauthenticated visitors to the wishlist slug
  instead of getting stuck on the loading screen

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Adriano Belisario
2026-05-03 21:02:10 +00:00
parent 2726be337e
commit 23114637ac
2 changed files with 13 additions and 8 deletions

View File

@@ -90,24 +90,25 @@ export async function POST(
allItems.splice(newSortOrder, 0, movingItem);
// Update all sortOrders in a transaction for atomicity
const updatedItem = await db.transaction(async (tx) => {
// Update all sortOrders
// Note: better-sqlite3 is synchronous, so no async/await in transaction
const updatedItem = db.transaction((tx) => {
for (let i = 0; i < allItems.length; i++) {
await tx
.update(wishlistItems)
tx.update(wishlistItems)
.set({
sortOrder: i,
updatedAt: new Date(),
})
.where(eq(wishlistItems.id, allItems[i].id));
.where(eq(wishlistItems.id, allItems[i].id))
.run();
}
// Get the updated moving item
const result = await tx
const result = tx
.select()
.from(wishlistItems)
.where(eq(wishlistItems.id, id))
.limit(1);
.limit(1)
.all();
return result[0];
});