refactor: simplify forwarding check in multi-bill-edit
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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<BillingLocation>("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<BillingLocation>("lokacije").updateOne(
|
||||
{ _id: locationId },
|
||||
{ $set: { billFwdStatus: "pending" } }
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user