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

Review Result ?

solutionbowl/bet-service · 815b10de
The code adds calculations for profit and exposure changes in the bet controller, supporting back and lay bets with clear comments explaining the logic. It enhances the multi bet APIs and introduces new P&L reporting flow, contributing to business value. However, the risk of bugs exists due to the complexity of multiplier calculations and the use of Number conversion without validation. No direct security issues are visible but lacks input sanitization or error handling.
Quality ?
75%
Security ?
60%
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/controllers/bet.controller.js:310
Issue / Evidence use of Number(currentOdd) without validation
Suggested Fix add input validation or use safer conversion
Missing Validation
Where src/controllers/bet.controller.js:327
Issue / Evidence use of Number(currentOdd) without validation
Suggested Fix add input validation or use safer conversion
Variable Profitchange Initialization
Where src/controllers/bet.controller.js:302
Issue / Evidence variable profitChange initialization
Suggested Fix consider initializing explicitly where used to improve clarity
Database Update Block
Where src/controllers/bet.controller.js:341
Issue / Evidence database update block
Suggested Fix ensure error handling is present after update operation
Insufficient Detail
Where commit message
Issue / Evidence insufficient detail
Suggested Fix improve description to explain the purpose and impact of new P&L report flow changes
Code Change Preview · src/controllers/bet.controller.js ?
Removed / Before Commit
- diff --git a/src/controllers/bet.controller.js b/src/controllers/bet.controller.js
- index 3ec31d9..12c9e3c 100644
- for (const r of market.odds) {
- const isSelectedRunner = String(r.runnerId) === String(runnerId);
- let exposureChange = 0;
- 
- if (isSelectedRunner) {
-             // Selected runner exposure
- if (odds_type === "back") {
-               // BACK: User risks stake (deduct from exposure)
-               exposureChange = -amount;
- } else {
-               // LAY: User risks liability (add to exposure)
-               exposureChange = amount * Number(currentOdd);
- }
- } else {
-             // Other runners exposure
- if (odds_type === "back") {
Added / After Commit
+ diff --git a/src/controllers/bet.controller.js b/src/controllers/bet.controller.js
+ index 3ec31d9..12c9e3c 100644
+ for (const r of market.odds) {
+ const isSelectedRunner = String(r.runnerId) === String(runnerId);
+ let exposureChange = 0;
+           let profitChange = 0;
+ 
+ if (isSelectedRunner) {
+             // Selected runner exposure (admin's perspective)
+ if (odds_type === "back") {
+               // BACK: If this runner wins, admin pays profit
+               // NOTE: odds are NET odds (profit multiplier), not gross
+               // Admin's loss = odds × stake (profit to pay)
+               const profit = Number(currentOdd) * amount;
+               exposureChange = profit;  // Admin's potential loss
+               profitChange = 0;  // No profit if this wins
+ } else {
+               // LAY: If this runner wins, admin wins the stake