Showing AI reviews for bet-service
Project AI Score ?
62%
Quality Avg ?
63%
Security Avg ?
59%
Reviews ?
92

Review Result ?

solutionbowl/bet-service · 6b158107
The commit adds logic to determine if an active leg is in the last position and adjusts exposure calculations accordingly. It improves calculation precision but lacks context and descriptive comments, reducing clarity and maintainability. Naming could be better clarified.
Quality ?
70%
Security ?
80%
Business Value ?
60%
Maintainability ?
65%
Issues & Suggested Fixes ?
1AI detects the issue
2Shows file, line, or evidence
3Suggests the fix to apply
Insufficient Description
Where commit message
Issue / Evidence insufficient description
Suggested Fix provide a detailed message explaining what problem this commit solves and the impact.
Unclear Coercion Logic
Where src/utils/multiBetExposure.js:64
Issue / Evidence unclear coercion logic
Suggested Fix clarify and ensure the fallback logic for position numbering is logically sound and documented.
Comment Clarity
Where src/utils/multiBetExposure.js:106
Issue / Evidence comment clarity
Suggested Fix expand the comment to describe why the last position settles full profit and implications.
Variable Naming
Where src/utils/multiBetExposure.js:140
Issue / Evidence variable naming
Suggested Fix consider renaming isLastPosition to something more descriptive like isAtFinalLeg for clarity.
Code Change Preview · src/utils/multiBetExposure.js ?
Removed / Before Commit
- diff --git a/src/utils/multiBetExposure.js b/src/utils/multiBetExposure.js
- index 1db1ccc..b2dbbf3 100644
- return { success: true, confirmedAmount };
- }
- 
- // Calculate profit for only the next active position.
- const legProfit = confirmedAmount * activeLeg.odds_matched;
- 
- // Get race market to find all runners
- const raceMarket = await RaceMarket.findOne({
- let exposureAmount = 0;
- 
- if (isSelectedRunner) {
-         // Selected runner: Platform pays profit if this runner wins
-         exposureAmount = -legProfit;
- } else {
- // Other runners: user loses the carried amount from previous won positions.
- exposureAmount = confirmedAmount;
Added / After Commit
+ diff --git a/src/utils/multiBetExposure.js b/src/utils/multiBetExposure.js
+ index 1db1ccc..b2dbbf3 100644
+ return { success: true, confirmedAmount };
+ }
+ 
+     const activeLegPosition = Number(activeLeg.position || activeLeg.leg_number || 1);
+     const maxPosition = sortedLegs.reduce((max, leg) => {
+       const position = Number(leg.position || leg.leg_number || 1);
+       return Math.max(max, position);
+     }, 0);
+     const isLastPosition = activeLegPosition === maxPosition;
+ 
+ // Calculate profit for only the next active position.
+ const legProfit = confirmedAmount * activeLeg.odds_matched;
+     const totalProfitIfActiveLegWins = (confirmedAmount - originalStake) + legProfit;
+ 
+ // Get race market to find all runners
+ const raceMarket = await RaceMarket.findOne({