From 2bc5cad82dc695cc4edf29843d47ece770d713f7 Mon Sep 17 00:00:00 2001 From: Knee Cola Date: Wed, 31 Dec 2025 10:24:27 +0100 Subject: [PATCH] refactor: simplify forwarding check in multi-bill-edit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed unnecessary loop when checking if bill forwarding should be triggered. Since we only need to determine if forwarding should happen once per location (after all bills are updated), we can check with just the first paid bill instead of looping through all updates. Benefits: - More efficient (no redundant checks for unpaid bills) - Clearer logic (one check per location, not per bill update) - Avoids confusion about checking bills that weren't marked as paid 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- web-app/app/lib/actions/monthActions.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/web-app/app/lib/actions/monthActions.ts b/web-app/app/lib/actions/monthActions.ts index e4b72e7..6df1b4d 100644 --- a/web-app/app/lib/actions/monthActions.ts +++ b/web-app/app/lib/actions/monthActions.ts @@ -231,16 +231,15 @@ export const updateMonth = withUser(async ( return; // Location not found } - // Check each bill update to see if it triggers forwarding - for (const update of locationUpdates) { - if (shouldUpdateBillFwdStatusWhenPayed(location, update.billId, update.paid)) { - // Update billFwdStatus to "pending" - await dbClient.collection("lokacije").updateOne( - { _id: locationId }, - { $set: { billFwdStatus: "pending" } } - ); - break; // Only need to set once per location - } + // Check if any paid bill triggers forwarding (only need to check once) + const firstPaidUpdate = locationUpdates.find(update => update.paid === true); + + if (firstPaidUpdate && shouldUpdateBillFwdStatusWhenPayed(location, firstPaidUpdate.billId, true)) { + // Update billFwdStatus to "pending" + await dbClient.collection("lokacije").updateOne( + { _id: locationId }, + { $set: { billFwdStatus: "pending" } } + ); } } );