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

Review Result ?

solutionbowl/tenant-service · fa4e1aac
This commit adds an API endpoint for updating the insurance status of a horse race. It includes validation of input data, error handling, and restricts access via middleware. The change has moderate quality and business impact but could be improved with stronger input validation and more descriptive commit messaging.
Quality ?
75%
Security ?
60%
Business Value ?
80%
Maintainability ?
73%
Issues & Suggested Fixes ?
1AI detects the issue
2Shows file, line, or evidence
3Suggests the fix to apply
Issue
Where commit message
Issue / Evidence issue
Suggested Fix write a more descriptive message explaining the purpose and impact of the update for clarity and better documentation
Missing Validation
Where src/controllers/horseracing/market.controller.js:683
Issue / Evidence validation
Suggested Fix add explicit validation on the 'insurance' input to ensure it is a boolean to prevent possible data inconsistency
Improve Error Handling
Where src/controllers/horseracing/market.controller.js:682
Issue / Evidence improve error handling
Suggested Fix add error handling for invalid request bodies and unexpected errors before accessing req.body properties
Security Issue
Where src/controllers/horseracing/market.controller.js:708
Issue / Evidence security
Suggested Fix consider logging less detailed error information to avoid leaking internal server details in production logs
Security Issue
Where src/routes/horseracing.routes.js:56
Issue / Evidence security
Suggested Fix ensure authMiddleware and roleMiddleware properly validate authorization to mitigate unauthorized access risk
Code Change Preview · src/controllers/horseracing/market.controller.js ?
Removed / Before Commit
- diff --git a/src/controllers/horseracing/market.controller.js b/src/controllers/horseracing/market.controller.js
- index 86041e3..f2fde19 100644
- }
- };
- 
- exports.getAssignedRaces = async (req, res) => {
- try {
- const puncherId = req.user.userId;
Added / After Commit
+ diff --git a/src/controllers/horseracing/market.controller.js b/src/controllers/horseracing/market.controller.js
+ index 86041e3..f2fde19 100644
+ }
+ };
+ 
+ exports.updateRaceInsurance = async (req, res) => {
+   try {
+     const { raceId, insurance } = req.body;
+ 
+     if (!mongoose.Types.ObjectId.isValid(raceId)) {
+       return res.status(400).json({ message: "Invalid Race ID" });
+     }
+ 
+     if (insurance === undefined || insurance === null) {
+       return res.status(400).json({ message: "Insurance is required" });
+     }
+ 
+     const updatedRace = await HorseRace.findByIdAndUpdate(
Removed / Before Commit
- diff --git a/src/models/HorseRace.js b/src/models/HorseRace.js
- index d6dfb05..5d0ad36 100644
- liveUrl: { type: String, default: null },
- 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 },
Added / After Commit
+ diff --git a/src/models/HorseRace.js b/src/models/HorseRace.js
+ index d6dfb05..5d0ad36 100644
+ liveUrl: { type: String, default: null },
+ status: { type: Boolean, default: true },
+ winnerSettle: { type: Boolean, default: false },
+   insurance_bet: { type: Boolean, default: false },
+ fancySettle: { type: Boolean, default: false },
+ winDeductionPercent: { type: Number, default: 0 },
+ placeDeductionPercent: { type: Number, default: 0 },
Removed / Before Commit
- diff --git a/src/routes/horseracing.routes.js b/src/routes/horseracing.routes.js
- index 076ecfb..f850b51 100644
- router.post("/races/:raceId/settle-fancy", authMiddleware, roleMiddleware("PLATFORM_ADMIN"), resultController.settleFancyMarket);
- router.post("/races/:eventId/revert-settle", authMiddleware, roleMiddleware("PLATFORM_ADMIN"), resultController.revertSettledMarket);
- 
- 
- 
- // Horse Routes
Added / After Commit
+ diff --git a/src/routes/horseracing.routes.js b/src/routes/horseracing.routes.js
+ index 076ecfb..f850b51 100644
+ router.post("/races/:raceId/settle-fancy", authMiddleware, roleMiddleware("PLATFORM_ADMIN"), resultController.settleFancyMarket);
+ router.post("/races/:eventId/revert-settle", authMiddleware, roleMiddleware("PLATFORM_ADMIN"), resultController.revertSettledMarket);
+ 
+ router.put("/update-race-insurance", authMiddleware, roleMiddleware("PLATFORM_ADMIN"), marketController.updateRaceInsurance);
+ 
+ 
+ // Horse Routes