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

Review Result ?

solutionbowl/tenant-service · 51d4023f
The commit adds runner position and jersey scraping data to the Horse controller and HorseList model and implements multi-bet settlement logic based on race results. It enhances business logic by supporting multi-leg bets settlement related to horse racing. The code is fairly clear and includes error handling, though there is room to improve logging and validation for robustness and security.
Quality ?
80%
Security ?
70%
Business Value ?
85%
Maintainability ?
80%
Issues & Suggested Fixes ?
1AI detects the issue
2Shows file, line, or evidence
3Suggests the fix to apply
Debug Console.log Statements
Where src/controllers/horseracing/result.controller.js:335
Issue / Evidence debug console.log statements
Suggested Fix replace with proper structured logging or remove to improve quality and security
Inefficient Loop With Database Calls (Raci...
Where src/controllers/horseracing/result.controller.js:367
Issue / Evidence inefficient loop with database calls (RacingBet.find inside a for loop)
Suggested Fix batch load all relevant data before loops to improve quality and lower bug risk
Missing Validation
Where src/controllers/horseracing/result.controller.js:323
Issue / Evidence lack of input parameter validation (raceId)
Suggested Fix validate inputs before queries to improve bug risk and security
Defaulting Status To True Without Clear So...
Where src/controllers/horseracing/horse.controller.js:153
Issue / Evidence defaulting status to true without clear source
Suggested Fix clarify or add validation to avoid logical errors
Swallowing Errors Silently In Settlemultib...
Where src/controllers/horseracing/result.controller.js:486
Issue / Evidence swallowing errors silently in settleMultiBetLegs
Suggested Fix add error reporting or retry mechanisms to avoid silent failures
Missing Validation
Where src/models/HorseList.js:17
Issue / Evidence no validation for position number and jersey URL
Suggested Fix add validation/schema constraints to improve data quality and security
Code Change Preview · src/controllers/horseracing/horse.controller.js ?
Removed / Before Commit
- diff --git a/src/controllers/horseracing/horse.controller.js b/src/controllers/horseracing/horse.controller.js
- index 123fa93..a0e3823 100644
- jockey: "$horses.jockey",
- trainer: "$horses.trainer",
- status: "$horses.status",
- createdAt: "$horses.createdAt",
- updatedAt: "$horses.updatedAt"
- },
- horse_name: h.horse_name,
- jockey: h.jockey,
- trainer: h.trainer,
-       status: h.status !== undefined ? h.status : true
- }));
- 
- const insertedHorses = await HorseList.insertMany(horseDocs);
- if (req.body.jockey) updateData.jockey = req.body.jockey;
- if (req.body.trainer) updateData.trainer = req.body.trainer;
- if (req.body.status !== undefined) updateData.status = req.body.status;
Added / After Commit
+ diff --git a/src/controllers/horseracing/horse.controller.js b/src/controllers/horseracing/horse.controller.js
+ index 123fa93..a0e3823 100644
+ jockey: "$horses.jockey",
+ trainer: "$horses.trainer",
+ status: "$horses.status",
+                   position: "$horses.position",
+                   jersey: "$horses.jersey",
+ createdAt: "$horses.createdAt",
+ updatedAt: "$horses.updatedAt"
+ },
+ horse_name: h.horse_name,
+ jockey: h.jockey,
+ trainer: h.trainer,
+       status: h.status !== undefined ? h.status : true,
+       position: h.position || null,  // Runner position number (from scraping)
+       jersey: h.jersey || null       // Jersey image URL (from scraping)
+ }));
+ 
Removed / Before Commit
- diff --git a/src/controllers/horseracing/result.controller.js b/src/controllers/horseracing/result.controller.js
- index 441f5bb..d0d81de 100644
- 
- await Promise.all(dbOps);
- 
- return res.json({
- success: true,
- message: "Market settled successfully",
- }
- };
- 
- ALL LEGS WON → MULTI-BET WON
- exports.settleFancyMarket = async (req, res) => {
- try {
- const { raceId } = req.params;
Added / After Commit
+ diff --git a/src/controllers/horseracing/result.controller.js b/src/controllers/horseracing/result.controller.js
+ index 441f5bb..d0d81de 100644
+ 
+ await Promise.all(dbOps);
+ 
+     // ═══════════════════════════════════════════════════════════════
+     // 🆕 MULTI-BET SETTLEMENT
+     // ═══════════════════════════════════════════════════════════════
+     // Settle all multi-bet legs for this race
+     await settleMultiBetLegs(eventObjectId);
+ 
+ return res.json({
+ success: true,
+ message: "Market settled successfully",
+ }
+ };
+ 
+ /**
Removed / Before Commit
- diff --git a/src/models/HorseList.js b/src/models/HorseList.js
- index b6a6710..1dfeff4 100644
- status: { type: Boolean, default: true },
- tote_odds: { type: Number, default: null },
- dead_heat: { type: Boolean, default: false },
-   is_withdrawn: { type: Boolean, default: false }
- }, { timestamps: true });
- 
- module.exports = mongoose.model("HorseList", HorseListSchema);
Added / After Commit
+ diff --git a/src/models/HorseList.js b/src/models/HorseList.js
+ index b6a6710..1dfeff4 100644
+ status: { type: Boolean, default: true },
+ tote_odds: { type: Number, default: null },
+ dead_heat: { type: Boolean, default: false },
+   is_withdrawn: { type: Boolean, default: false },
+ 
+   // Runner scraping data
+   position: { type: Number, default: null },  // Runner position number
+   jersey: { type: String, default: null }     // Jersey image URL
+ }, { timestamps: true });
+ 
+ module.exports = mongoose.model("HorseList", HorseListSchema);