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

Review Result ?

solutionbowl/tenant-service · b86c8e6c
The commit adds handling for race status including marking races as VOID and disabling markets accordingly. It introduces new code to update race statuses and prevents void races from appearing in certain website queries. The implementation is straightforward but lacks comments and comprehensive error handling, which could improve maintainability and robustness. Overall it addresses business logic but could be improved in quality and bug risk aspects.
Quality ?
75%
Security ?
80%
Business Value ?
70%
Maintainability ?
68%
Issues & Suggested Fixes ?
1AI detects the issue
2Shows file, line, or evidence
3Suggests the fix to apply
No Error Handling During Database Queries...
Where src/controllers/horseracing/result.controller.js:2885-2894
Issue / Evidence No error handling during database queries and save operations
Suggested Fix add try/catch blocks to handle potential errors and improve robustness
Missing Validation
Where src/controllers/horseracing/race.controller.js:118,153
Issue / Evidence Implicit conversion and string manipulation of race_status without validation
Suggested Fix add validation to ensure race_status values are valid enums before usage
Use Of Spread Syntax Without Deep Clone
Where src/controllers/horseracing/result.controller.js:2887
Issue / Evidence use of spread syntax without deep clone
Suggested Fix consider cloning nested objects if markets contain nested mutable objects to avoid side effects
Vague Description
Where commit message
Issue / Evidence vague description
Suggested Fix improve commit message to clearly summarize the functional changes for better future tracking
Code Change Preview · src/controllers/horseracing/race.controller.js ?
Removed / Before Commit
- diff --git a/src/controllers/horseracing/race.controller.js b/src/controllers/horseracing/race.controller.js
- index 4ecf00b..11e5533 100644
- start_time: 1,
- liveUrl: 1,
- status: 1,
- insurance_bet: 1,
- allow_multi_bet: 1,
- createdAt: 1,
- 
- exports.createRace = async (req, res) => {
- try {
-     const { event_id, race_no, race_name, distance, start_time, liveUrl, status, raceType, bet_start_time, bet_end_time, betfairEventId, scrolling_text } = req.body;
- 
- if (!mongoose.Types.ObjectId.isValid(event_id))
- return res.status(400).json({ message: "Invalid event ID" });
- bet_end_time: bet_end_time || null,
- betfairEventId,
- scrolling_text: scrolling_text || "",
Added / After Commit
+ diff --git a/src/controllers/horseracing/race.controller.js b/src/controllers/horseracing/race.controller.js
+ index 4ecf00b..11e5533 100644
+ start_time: 1,
+ liveUrl: 1,
+ status: 1,
+           race_status: 1,
+ insurance_bet: 1,
+ allow_multi_bet: 1,
+ createdAt: 1,
+ 
+ exports.createRace = async (req, res) => {
+ try {
+     const { event_id, race_no, race_name, distance, start_time, liveUrl, status, race_status, raceType, bet_start_time, bet_end_time, betfairEventId, scrolling_text } = req.body;
+ 
+ if (!mongoose.Types.ObjectId.isValid(event_id))
+ return res.status(400).json({ message: "Invalid event ID" });
+ bet_end_time: bet_end_time || null,
+ betfairEventId,
Removed / Before Commit
- diff --git a/src/controllers/horseracing/result.controller.js b/src/controllers/horseracing/result.controller.js
- index db3cce6..7d89d74 100644
- $or: [{ race_id: raceId }, { race_id: raceObjectId }],
- });
- 
- await HorseRace.findByIdAndUpdate(raceObjectId, {
- $set: {
- race_void: true,
- voidedAt: now,
- },
- });
- ),
- );
- 
-     const raceMarket = await RaceMarket.findOne({ race_id: raceObjectId }).lean();
- if (raceMarket?.market_data) {
- await emitRaceOdds(raceId, raceMarket.market_data);
- }
Added / After Commit
+ diff --git a/src/controllers/horseracing/result.controller.js b/src/controllers/horseracing/result.controller.js
+ index db3cce6..7d89d74 100644
+ $or: [{ race_id: raceId }, { race_id: raceObjectId }],
+ });
+ 
+     const raceMarket = await RaceMarket.findOne({ race_id: raceObjectId });
+     if (raceMarket) {
+       const disableMarkets = (markets = []) =>
+         Array.isArray(markets)
+           ? markets.map((market) => ({ ...market, is_active: false }))
+           : markets;
+ 
+       raceMarket.markets = disableMarkets(raceMarket.markets);
+       raceMarket.market_data = disableMarkets(raceMarket.market_data);
+       raceMarket.markModified("markets");
+       raceMarket.markModified("market_data");
+       await raceMarket.save();
+     }
Removed / Before Commit
- diff --git a/src/controllers/horseracing/website.controller.js b/src/controllers/horseracing/website.controller.js
- index 22d0670..1b39edc 100644
- const query = {
- allow_multi_bet: true,
- status: true,
-       winnerSettle: false
- };
- 
- if (event_id) {
Added / After Commit
+ diff --git a/src/controllers/horseracing/website.controller.js b/src/controllers/horseracing/website.controller.js
+ index 22d0670..1b39edc 100644
+ const query = {
+ allow_multi_bet: true,
+ status: true,
+       race_status: { $ne: "VOID" },
+       race_void: { $ne: true },
+ };
+ 
+ if (event_id) {
Removed / Before Commit
- diff --git a/src/models/HorseRace.js b/src/models/HorseRace.js
- index 5c7d643..31e689e 100644
- start_time: { type: Date, required: true },
- 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 },
Added / After Commit
+ diff --git a/src/models/HorseRace.js b/src/models/HorseRace.js
+ index 5c7d643..31e689e 100644
+ start_time: { type: Date, required: true },
+ liveUrl: { type: String, default: null },
+ status: { type: Boolean, default: true },
+   race_status: { type: String, enum: ["ACTIVE", "VOID"], default: "ACTIVE" },
+ winnerSettle: { type: Boolean, default: false },
+ insurance_bet: { type: Boolean, default: false },
+ fancySettle: { type: Boolean, default: false },