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

Review Result ?

solutionbowl/bet-service · bcca0cd5
The commit adds a new function to recalculate place exposure and modifies the placeBet controller flow with validation and bet placing logic. It involves aggregation queries, checks on wallet balance, race and market validation, and exposure updates. While it introduces valuable business logic, code style and clarity could be improved, and some security concerns around input validation and error handling remain.
Quality ?
70%
Security ?
60%
Business Value ?
80%
Maintainability ?
65%
Issues & Suggested Fixes ?
1AI detects the issue
2Shows file, line, or evidence
3Suggests the fix to apply
Commit Message Is Unclear And Full Of Typo...
Where commit message
Issue / Evidence commit message is unclear and full of typos
Suggested Fix write a clear and descriptive message without spelling errors
Missing 'Use Strict' Or Module Encapsulati...
Where src/controllers/test.controller.js:1
Issue / Evidence missing 'use strict' or module encapsulation
Suggested Fix add module scoping for better quality
Long Function
Where src/controllers/test.controller.js:8
Issue / Evidence complex aggregation query without comments
Suggested Fix add comments explaining the purpose of each pipeline stage to improve maintainability
Direct Number Conversion Without Nan Check
Where src/controllers/test.controller.js:44
Issue / Evidence direct Number conversion without NaN check
Suggested Fix add validation to check for NaN values after Number conversion to prevent bugs
Odds Type String Comparison Prone To Case...
Where src/controllers/test.controller.js:47
Issue / Evidence odds_type string comparison prone to case issues
Suggested Fix normalize odds_type (e.g. convert to lower case) before checks to improve robustness
Use Of Math.abs And Math.min With Zero Is...
Where src/controllers/test.controller.js:63
Issue / Evidence use of Math.abs and Math.min with zero is confusing
Suggested Fix clarify intent or add comments for better code clarity
Missing Validation
Where src/controllers/test.controller.js:143
Issue / Evidence wallet balance check on client-provided amount without revalidation
Suggested Fix revalidate wallet balance after concurrent updates to avoid race conditions
Missing Check For Valid Objectid Format Fo...
Where src/controllers/test.controller.js:150
Issue / Evidence missing check for valid ObjectId format for raceId
Suggested Fix add validation to prevent potential injection or crashes
Missing Check For Runnerid Validity And Ty...
Where src/controllers/test.controller.js:190
Issue / Evidence missing check for runnerId validity and type consistency
Suggested Fix add robust validation for runnerId check to prevent errors
Usage Of Accept Any Odds With Direct Null...
Where src/controllers/test.controller.js:197
Issue / Evidence usage of accept_any_odds with direct null check on currentOdd
Suggested Fix clarify or expand condition for better error handling
Catch Block Missing Detailed Error Logging
Where src/controllers/test.controller.js:91
Issue / Evidence catch block missing detailed error logging
Suggested Fix add logging for exceptions to improve debugging and security incident detection
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 a776079..7d16862 100644
- runnerId,
- });
- 
-         market.odds.forEach((r) => {
-           if (String(r.runnerId) === String(runnerId)) {
-             r.exposureProfit = recalculated.exposureProfit;
-             r.exposure = recalculated.exposure;
-           }
-         });
- } else {
-         market.odds.forEach((r) => {
-           if (r.exposure === undefined || r.exposure === null) {
-             r.exposure = 0;
-           }
- 
-           const isSelectedRunner = String(r.runnerId) === String(runnerId);
Added / After Commit
+ diff --git a/src/controllers/bet.controller.js b/src/controllers/bet.controller.js
+ index a776079..7d16862 100644
+ runnerId,
+ });
+ 
+ } else {
+ 
+ for (const r of market.odds) {
+ const isSelectedRunner = String(r.runnerId) === String(runnerId);
+ race_id: new mongoose.Types.ObjectId(raceId),
+ });
+ 
+       emitRaceOdds(raceId, racemarket.market_data, tenant_id);
+ 
+ await Wallet.updateOne(
+ { userId: new mongoose.Types.ObjectId(user_id) },
Removed / Before Commit
- diff --git a/src/controllers/test.controller.js b/src/controllers/test.controller.js
- new file mode 100644
- index 0000000..985b3f6
- \ No newline at end of file
Added / After Commit
+ diff --git a/src/controllers/test.controller.js b/src/controllers/test.controller.js
+ new file mode 100644
+ index 0000000..985b3f6
+ const recalculatePlacesExposure = async ({
+     user_id,
+     tenant_id,
+     raceId,
+     marketId,
+     runnerId,
+ }) => {
+     const bets = await Bet.aggregate([
+         {
+             $match: {
+                 user_id: new mongoose.Types.ObjectId(user_id),
+                 event_id: new mongoose.Types.ObjectId(raceId),
+                 bet_status: "ACCEPTED",
+             },
+         },
Removed / Before Commit
- diff --git a/src/utils/socketClient.js b/src/utils/socketClient.js
- index a1b8ad8..9f3d898 100644
- return socket;
- };
- 
- const emitRaceOdds = async (raceId, oddsData, tenantId) => {
- const s = getSocket();
- 
-   // 🟢 1. SUPER ADMIN (GLOBAL - same as before)
-   s.emit("raceOddsAdmin", {
-     raceId,
-     oddsData // already contains global exposure
-   });
- 
-   // 🔵 2. TENANT (with exposure merge)
- if (tenantId) {
- try {
-       // 👉 Get tenant exposure
Added / After Commit
+ diff --git a/src/utils/socketClient.js b/src/utils/socketClient.js
+ index a1b8ad8..9f3d898 100644
+ return socket;
+ };
+ 
+ const emitRaceOdds = async (raceId, oddsData, tenantId = null) => {
+ const s = getSocket();
+ 
+   // 1️⃣ Emit raw odds to everyone (no exposure mixed in)
+   s.emit(`raceOdds`, { raceId, oddsData });
+ 
+   // 2️⃣ Admin → global exposure (no tenant filter)
+   try {
+     const globalExposure = await getExposureData({ raceId });
+     s.emit("raceExposureAdmin", {
+       raceId,
+       exposure: globalExposure,
+     });