[Bug]: extra_distance_km column referenced in loadRoutes.js distance filter and sort is never populated#838
Conversation
|
@KanishJebaMathewM I have submitted the fix. Please let me know if any changes are needed! |
|
🎉 Thank you for your contribution! Your pull request has been received and will be reviewed shortly. If you enjoy the project, please consider giving the repository a ⭐. You can also follow my GitHub profile to stay updated on future open-source projects. Thanks for being part of the community! 🚀 |
📝 WalkthroughWalkthroughDuring order creation, the ChangesFix extra_distance_km population on order creation
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/api/src/routes/orderRoutes.js`:
- Line 272: `extra_distance_km` is being populated from `pricing.distanceKm`,
which is a 2-decimal value, but the `load_offers.extra_distance_km` column is an
integer. Update the `orderRoutes` insert/mapping so the value matches the stored
type by rounding or otherwise converting it before insert, and keep the
`pricing.distanceKm` usage consistent in the relevant offer creation flow. If
decimal precision is actually needed, adjust the database schema instead of
relying on an implicit cast.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 49efd53c-cf65-4c98-95f9-731bf7beaad2
📒 Files selected for processing (1)
backend/api/src/routes/orderRoutes.js
| fuel_cost: pricing.fuelCost, | ||
| toll_cost: pricing.tollEstimate, | ||
| net_profit: pricing.netProfit, | ||
| extra_distance_km: pricing.distanceKm, |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Align extra_distance_km type with stored value (Line 272).
pricing.distanceKm is 2-decimal, but load_offers.extra_distance_km is defined as int (docs/supabase_setup.sql). This creates an implicit cast/precision loss at insert time and weakens distance filter/sort accuracy.
💡 Proposed fix
- extra_distance_km: pricing.distanceKm,
+ extra_distance_km: Math.round(pricing.distanceKm),(If decimal precision is required, migrate the DB column to a numeric type instead.)
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| extra_distance_km: pricing.distanceKm, | |
| extra_distance_km: Math.round(pricing.distanceKm), |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@backend/api/src/routes/orderRoutes.js` at line 272, `extra_distance_km` is
being populated from `pricing.distanceKm`, which is a 2-decimal value, but the
`load_offers.extra_distance_km` column is an integer. Update the `orderRoutes`
insert/mapping so the value matches the stored type by rounding or otherwise
converting it before insert, and keep the `pricing.distanceKm` usage consistent
in the relevant offer creation flow. If decimal precision is actually needed,
adjust the database schema instead of relying on an implicit cast.
fc2f305
into
KanishJebaMathewM:main
|
🎉 Thank you for your contribution! Your pull request has been merged successfully. We appreciate your work and look forward to your future contributions. 🚀 |
Fix
Added
extra_distance_kmto theload_offersinsert in the order creation handler. The value comes frompricing.distanceKmwhich is already computed bycomputeOrderPricing()(either from OSRM road distance or haversine fallback).Changes
backend/api/src/routes/orderRoutes.js (line 272)
extra_distance_km: pricing.distanceKmalongside existingfreight_value,fuel_cost,toll_cost,net_profitGET /api/loadsendpoint already filters by.lte("extra_distance_km", maxDistance)and sorts byextra_distance_km— these will now work correctlyCloses #739
Summary by CodeRabbit