fix: fuel-logs enhanced repository methods return raw rows without mapping, breaking numeric type contract #244
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Per the audit performed for #241, the "enhanced" methods in
backend/src/features/fuel-logs/data/fuel-logs.repository.ts(createEnhanced,findByVehicleIdEnhanced,updateEnhanced) return raw pg rows instead of going throughmapRow. The legacymapRowcorrectly coerces all decimal fields withparseFloat, but the enhanced path bypasses it.Affected Fields (enhanced methods only)
Returned as strings instead of numbers:
fuelUnits—DECIMAL(8,3)costPerUnit—DECIMAL(6,3)tripDistance—DECIMAL(10,3)(Other legacy fields like
totalCost,gallons,pricePerGallonare not affected because the legacymapRowcoerces them.)Investigation Required (before fixing)
createEnhanced/findByVehicleIdEnhanced/updateEnhancedvs. the legacy methods? (Look for "enhanced" in route handlers.)Number()defensively (e.g. fuel-logs hooks or analytics components), fixing the mapper will make those redundant."3.5" + "1.2"="3.51.2"in JS).Suggested Fix
Add a mapper for the enhanced shape (or extend the legacy
mapRow) that coerces all decimal fields withparseFloatorNumber(). Route all three enhanced methods through it.Acceptance Criteria
mapRowor add a siblingmapEnhancedRow.createEnhanced,findByVehicleIdEnhanced,updateEnhancedwith the mapper.Number()calls in consumers that become unnecessary.Related