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

Review Result ?

solutionbowl/tenant-service · 4596c531
The commit introduces a concept of deduction amount and applies it to payouts in a horse racing betting controller. However, the deductionPercent is initialized to 0 and never updated, making the deduction ineffective. The logic for calculating payoutAdded varies by odds type but may benefit from more robust handling of edge cases and variable initialization. There are no apparent security issues such as injection or exposure of sensitive information, but the lack of meaningful deductions reduces business value.
Quality ?
60%
Security ?
70%
Business Value ?
50%
Maintainability ?
60%
Issues & Suggested Fixes ?
1AI detects the issue
2Shows file, line, or evidence
3Suggests the fix to apply
Deductionpercent Is Initialized To And N...
Where src/controllers/horseracing/result.controller.js:103
Issue / Evidence deductionPercent is initialized to 0 and never updated
Suggested Fix implement logic to set deductionPercent based on business rules before use
Mixed Calculations For Payout And Payoutad...
Where src/controllers/horseracing/result.controller.js:111-121
Issue / Evidence mixed calculations for payout and payoutAdded may be confusing and error-prone
Suggested Fix simplify and add comments to clarify payout calculation logic
Use Of Tofixed(2) For Balance Update May C...
Where src/controllers/horseracing/result.controller.js:133
Issue / Evidence use of toFixed(2) for balance update may cause floating point rounding issues
Suggested Fix consider using a more precise rounding method or monetary library
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 d36e2df..51827c5 100644
- if (isWinner) {
- let payout = 0;
- let payoutAdded = 0;
- 
-         if (oddsType === "back") {
-           payout = Number(bet.return_amount || 0); // full return
-           payoutAdded = Number(bet.bet_amount || 0) + Number(bet.return_amount || 0);
-         } else if (oddsType === "lay") {
-           payout = Number(bet.bet_amount || 0) + Number(bet.liability_amount || 0);
-           payoutAdded = Number(bet.bet_amount || 0) + Number(bet.liability_amount || 0);
-         }
- 
- if (marketName === "WIN") {
- deductionPercent = Number(win_deduction || 0);
- deductionPercent = Number(places_deduction || 0);
- }
Added / After Commit
+ diff --git a/src/controllers/horseracing/result.controller.js b/src/controllers/horseracing/result.controller.js
+ index d36e2df..51827c5 100644
+ if (isWinner) {
+ let payout = 0;
+ let payoutAdded = 0;
+         let deductionAmount = 0;
+         let deductionPercent = 0;
+ 
+ if (marketName === "WIN") {
+ deductionPercent = Number(win_deduction || 0);
+ deductionPercent = Number(places_deduction || 0);
+ }
+ 
+         if (oddsType === "back") {
+           payout = Number(bet.return_amount || 0); // full return
+           deductionAmount = (Number(bet.return_amount || 0) * deductionPercent) / 100;
+           const finalCreditAmount = Number(bet.return_amount || 0) - deductionAmount;
+           payoutAdded = Number(bet.bet_amount || 0) + finalCreditAmount;