AI Review Center
Commit Review Workspace ?
Select a commit on the left to inspect quality, security, business value, findings, and suggested code changes.
Project AI Score
?
62%
Quality Avg
?
63%
Security Avg
?
59%
Reviews
?
92
Review Result ?
solutionbowl/bet-service · 4e1f5041
The commit introduces an option to forcibly set a specific leg as 'WON' during multi-bet exposure calculation. This adds flexibility but lacks input validation and code comments explaining the purpose and usage of forceWonLegNumber. The code changes appear logically consistent but would benefit from better documentation and some validation to reduce potential misuse or bugs.
Quality
?
75%
Security
?
80%
Business Value
?
70%
Maintainability
?
73%
Issues & Suggested Fixes
?
1AI detects the issue
2Shows file, line, or evidence
3Suggests the fix to apply
Missing Validation
Where
src/utils/multiBetExposure.js:13
Issue / Evidence
no validation on options.forceWonLegNumber
Suggested Fix
add validation to ensure forceWonLegNumber is a valid leg number
Missing Function Level Comment
Where
src/utils/multiBetExposure.js:11
Issue / Evidence
missing function-level comment
Suggested Fix
add JSDoc or comments to explain calculateMultiBetExposures and the effect of forceWonLegNumber option
Implicit String Checks For Legstatus
Where
src/utils/multiBetExposure.js:29
Issue / Evidence
implicit string checks for legStatus
Suggested Fix
consider using constants or enums for legStatus values to improve code clarity
Lack Of Detail
Where
commit message
Issue / Evidence
lack of detail
Suggested Fix
expand commit message to explain the rationale and implications of adding forceWonLegNumber option
Code Change Preview · src/utils/multiBetExposure.js
?
Removed / Before Commit
- diff --git a/src/utils/multiBetExposure.js b/src/utils/multiBetExposure.js - index 14061d2..d0ae2c6 100644 - * Uses cascading calculation based on confirmed won legs - * Creates exposure for ALL runners in each pending leg (like WINNER market) - */ - async function calculateMultiBetExposures(betId, userId, tenantId, legs, originalStake) { - try { - // Calculate confirmed amount up to last won leg - const sortedLegs = await RacingBet.find({ bet_id: betId }) - .sort({ leg_number: 1 }); - - // Find last won leg - for (const leg of sortedLegs) { - if (leg.leg_status === "WON") { - const legProfit = confirmedAmount * leg.odds_matched; - confirmedAmount = confirmedAmount + legProfit; - } else if (leg.leg_status === "LOST") { - // If any leg lost, no exposures
Added / After Commit
+ diff --git a/src/utils/multiBetExposure.js b/src/utils/multiBetExposure.js + index 14061d2..d0ae2c6 100644 + * Uses cascading calculation based on confirmed won legs + * Creates exposure for ALL runners in each pending leg (like WINNER market) + */ + async function calculateMultiBetExposures(betId, userId, tenantId, legs, originalStake, options = {}) { + try { + const forceWonLegNumber = options.forceWonLegNumber + ? Number(options.forceWonLegNumber) + : null; + + // Calculate confirmed amount up to last won leg + const sortedLegs = await RacingBet.find({ bet_id: betId }) + .sort({ leg_number: 1 }); + + // Find last won leg + for (const leg of sortedLegs) { + const legStatus = forceWonLegNumber === Number(leg.leg_number)