Showing AI reviews for tenant-service
Project AI Score ?
67%
Quality Avg ?
69%
Security Avg ?
64%
Reviews ?
143

Review Result ?

solutionbowl/tenant-service · 8c31d3fe
The commit introduces new logic for settling multi-leg bets including profit calculations, deductions, and updating bet records. The code is generally well-structured and includes handling for various leg statuses, which improves business value by enabling multi-bet functionality. The addition of default values in the schema is good to prevent undefined errors. However, there are no tests included in the diff to validate this new logic and edge cases are not fully explained. Some numeric conversions could be more defensive to prevent NaNs or unexpected results. Documentation and more detailed commit message would improve clarity and maintainability. Security impact is limited but proper input validation and calculation integrity should be monitored.
Quality ?
80%
Security ?
75%
Business Value ?
85%
Maintainability ?
80%
Issues & Suggested Fixes ?
1AI detects the issue
2Shows file, line, or evidence
3Suggests the fix to apply
Non Descriptive Commit Message
Where commit message
Issue / Evidence non-descriptive commit message
Suggested Fix provide a detailed description of changes including rationale and impact
Missing Validation
Where src/controllers/horseracing/result.controller.js:24
Issue / Evidence input values converted without validation
Suggested Fix add validation to ensure numeric fields are safe to convert and used values are within expected ranges
No Error Handling In Crucial Calculation
Where src/controllers/horseracing/result.controller.js:35
Issue / Evidence no error handling in crucial calculation
Suggested Fix add try/catch or validation to prevent failure or incorrect carry amount calculation
Function Settlemultibetlegs Is Large And D...
Where src/controllers/horseracing/result.controller.js:566
Issue / Evidence function settleMultiBetLegs is large and does multiple things
Suggested Fix break down into smaller functions for better readability and easier testing
Calculation Followed By Db Update Without...
Where src/controllers/horseracing/result.controller.js:820
Issue / Evidence calculation followed by DB update without transaction
Suggested Fix ensure atomicity or consider transactions to reduce risk of partial updates
Duplicate Logic
Where src/controllers/horseracing/test.controller.js:22
Issue / Evidence profit calculation logic duplicated
Suggested Fix reuse utility functions for consistency and maintenance
Sortmultilegsbyposition Function Could Han...
Where src/controllers/horseracing/result.controller.js:18
Issue / Evidence sortMultiLegsByPosition function could handle missing positions more explicitly
Suggested Fix add comments or stricter handling for missing position or leg_number to avoid misordering
Code Change Preview · src/controllers/horseracing/result.controller.js ?
Removed / Before Commit
- diff --git a/src/controllers/horseracing/result.controller.js b/src/controllers/horseracing/result.controller.js
- index d6e5494..245a8a2 100644
- ? new mongoose.Types.ObjectId(id)
- : id;
- 
- async function updateImmediateParentBalances(userPLRows = []) {
- const UPLINE_BALANCE_ROLES = new Set(["MASTER", "SUPER_ADMIN"]);
- const totalsByUser = new Map();
- }
- }
- 
- if (acceptedBets.length === 0) {
-       await settleMultiBetLegs(eventObjectId);
- return res.json({ success: true, message: "No accepted bets to settle for this race." });
- }
- 
- const settlementLedgerRows = [];
- const now = new Date();
Added / After Commit
+ diff --git a/src/controllers/horseracing/result.controller.js b/src/controllers/horseracing/result.controller.js
+ index d6e5494..245a8a2 100644
+ ? new mongoose.Types.ObjectId(id)
+ : id;
+ 
+ const INACTIVE_MULTI_LEG_STATUSES = new Set(["VOID", "WITHDRAWN"]);
+ 
+ const sortMultiLegsByPosition = (legs = []) =>
+   [...legs].sort((a, b) =>
+     Number(a.position || a.leg_number || 0) - Number(b.position || b.leg_number || 0)
+   );
+ 
+ const getMultiLegProfit = (carryAmount, leg, useStoredWonProfit = true) => {
+   if (useStoredWonProfit && String(leg.leg_status || "") === "WON") {
+     const storedNetProfit = Number(leg.net_profit || 0);
+     const hasStoredProfit = Number(leg.gross_profit || 0) > 0 ||
+       Number(leg.deduction_percent || 0) > 0 ||
+       Number(leg.deduction_amount || 0) > 0;
Removed / Before Commit
- diff --git a/src/controllers/horseracing/test.controller.js b/src/controllers/horseracing/test.controller.js
- index 999e996..76a142d 100644
- for (const leg of [...legs].sort((a, b) =>
- Number(a.position || a.leg_number || 0) - Number(b.position || b.leg_number || 0)
- )) {
-     totalReturn += totalReturn * Number(leg.odds_matched || 0);
- }
- 
- totalReturn = Math.round(totalReturn);
Added / After Commit
+ diff --git a/src/controllers/horseracing/test.controller.js b/src/controllers/horseracing/test.controller.js
+ index 999e996..76a142d 100644
+ for (const leg of [...legs].sort((a, b) =>
+ Number(a.position || a.leg_number || 0) - Number(b.position || b.leg_number || 0)
+ )) {
+     const storedNetProfit = Number(leg.net_profit || 0);
+     const hasStoredProfit = Number(leg.gross_profit || 0) > 0 ||
+       Number(leg.deduction_percent || 0) > 0 ||
+       Number(leg.deduction_amount || 0) > 0;
+     const profit = String(leg.leg_status || "") === "WON" && hasStoredProfit
+       ? storedNetProfit
+       : totalReturn * Number(leg.odds_matched || 0);
+ 
+     totalReturn += profit;
+ }
+ 
+ totalReturn = Math.round(totalReturn);
Removed / Before Commit
- diff --git a/src/models/RacingBet.js b/src/models/RacingBet.js
- index d049332..d87f7d4 100644
- // Multi-bet support
- leg_number: { type: Number, default: 1 },
- position: { type: Number, default: 1 },
- leg_status: {
- type: String,
- enum: ["PENDING", "WON", "LOST", "VOID", "WITHDRAWN"],
Added / After Commit
+ diff --git a/src/models/RacingBet.js b/src/models/RacingBet.js
+ index d049332..d87f7d4 100644
+ // Multi-bet support
+ leg_number: { type: Number, default: 1 },
+ position: { type: Number, default: 1 },
+   stake_at_leg: { type: Number, default: 0 },
+   gross_profit: { type: Number, default: 0 },
+   deduction_percent: { type: Number, default: 0 },
+   deduction_amount: { type: Number, default: 0 },
+   net_profit: { type: Number, default: 0 },
+ leg_status: {
+ type: String,
+ enum: ["PENDING", "WON", "LOST", "VOID", "WITHDRAWN"],