fix: Fuel Logs API 500 error - repository snake_case mismatch (#47) #48
Reference in New Issue
Block a user
Delete Branch "issue-47-fix-fuel-logs-api"
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
toEnhancedResponse()expects snake_case, causingRangeError: Invalid time valueonnew Date(row.created_at)mapRow()calls from all enhanced repository methodsRoot Cause
The enhanced repository methods (
findByUserIdEnhanced,findByVehicleIdEnhanced, etc.) were incorrectly callingthis.mapRow()which converts snake_case database columns to camelCase TypeScript properties. However, the service'stoEnhancedResponse()method expects raw database rows with snake_case properties.When
toEnhancedResponse()triednew Date(row.created_at).toISOString()withrow.created_atbeingundefined(because mapRow converted it tocreatedAt), it threwRangeError: Invalid time value.Changes
Fixed 7 methods in
fuel-logs.repository.ts:createEnhanced(line 296)findByVehicleIdEnhanced(line 304)findByUserIdEnhanced(line 312)findByIdEnhanced(line 317)getPreviousLogByOdometer(line 325)getLatestLogForVehicle(line 333)updateEnhanced(line 419)Test Plan
Fixes #47