fix: sync reorder transaction + redirect unauthenticated users to wishlist
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
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:
@@ -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];
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user