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

Review Result ?

solutionbowl/tenant-service · 1c4f5b78
This commit introduces application of win and place deductions during payout calculation, with new fields added to the HorseRace model to track deduction percentages. The logic clearly distinguishes deduction based on market name and correctly calculates the final credit. However, there is no input validation or error handling for deduction percentages and floating point rounding might cause minor inaccuracies.
Quality ?
80%
Security ?
70%
Business Value ?
85%
Maintainability ?
70%
Issues & Suggested Fixes ?
1AI detects the issue
2Shows file, line, or evidence
3Suggests the fix to apply
Missing Validation
Where src/controllers/horseracing/result.controller.js:112
Issue / Evidence potential unsafe conversion of deduction percent without validation
Suggested Fix validate and sanitize deduction inputs before use
Numeric Update Uses Tofixed Which Returns...
Where src/controllers/horseracing/result.controller.js:130
Issue / Evidence numeric update uses toFixed which returns a string
Suggested Fix convert to number explicitly after rounding for safe DB numeric increment
Floating Point Arithmetic Used Directly Fo...
Where src/controllers/horseracing/result.controller.js:117
Issue / Evidence floating point arithmetic used directly for currency calculation
Suggested Fix consider using fixed-point library or integer cents to avoid rounding errors
Missing Validation
Where src/models/HorseRace.js:14
Issue / Evidence deduction fields have no validation or range enforcement
Suggested Fix add schema validation for deduction percentages to ensure they are between 0 and 100
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 c1723f3..d36e2df 100644
- 
- // 4. Update the bet document and grant wallet payout
- if (isWinner) {
-         // await Bet.findByIdAndUpdate(bet._id, { bet_status: "WON", updatedAt: new Date() });
-         // // Credit the User Wallet using atomic $inc operation with return_amount
-         // if (bet.return_amount && bet.user_id) {
-         //   await Wallet.findOneAndUpdate({ userId: new mongoose.Types.ObjectId(bet.user_id) }, { $inc: { balance: Number(bet.return_amount) } });
-         // }
- let payout = 0;
- let payoutAdded = 0;
- 
- payoutAdded = Number(bet.bet_amount || 0) + Number(bet.liability_amount || 0);
- }
- 
- await Bet.findByIdAndUpdate(bet._id, {
- bet_status: "WON",
Added / After Commit
+ diff --git a/src/controllers/horseracing/result.controller.js b/src/controllers/horseracing/result.controller.js
+ index c1723f3..d36e2df 100644
+ 
+ // 4. Update the bet document and grant wallet payout
+ if (isWinner) {
+ let payout = 0;
+ let payoutAdded = 0;
+ 
+ payoutAdded = Number(bet.bet_amount || 0) + Number(bet.liability_amount || 0);
+ }
+ 
+         if (marketName === "WIN") {
+           deductionPercent = Number(win_deduction || 0);
+         } else if (["2PLACES", "3PLACES", "4PLACES"].includes(marketName)) {
+           deductionPercent = Number(places_deduction || 0);
+         }
+ 
+         const deductionAmount = (payoutAdded * deductionPercent) / 100;
Removed / Before Commit
- diff --git a/src/models/HorseRace.js b/src/models/HorseRace.js
- index 4509aa8..d6dfb05 100644
- status: { type: Boolean, default: true },
- winnerSettle: { type: Boolean, default: false },
- fancySettle: { type: Boolean, default: false },
- raceType: { type: String, default: "IndianManual" },
- betStartBeforeInMin: { type: Number, default: 5 },
- betfairEventId: { type: String, default: "" }
Added / After Commit
+ diff --git a/src/models/HorseRace.js b/src/models/HorseRace.js
+ index 4509aa8..d6dfb05 100644
+ status: { type: Boolean, default: true },
+ winnerSettle: { type: Boolean, default: false },
+ fancySettle: { type: Boolean, default: false },
+   winDeductionPercent: { type: Number, default: 0 },
+   placeDeductionPercent: { type: Number, default: 0 },
+   fancyDeductionPercent: { type: Number, default: 0 },
+ raceType: { type: String, default: "IndianManual" },
+ betStartBeforeInMin: { type: Number, default: 5 },
+ betfairEventId: { type: String, default: "" }