Fix enhanced repository methods returning mapped (camelCase) rows instead of raw database rows (snake_case)
Service's toEnhancedResponse() expects snake_case, causing RangeError: Invalid time value on new Date(row.created_at)
Removed mapRow() calls from all enhanced repository methods
Root Cause
The enhanced repository methods (findByUserIdEnhanced, findByVehicleIdEnhanced, etc.) were incorrectly calling this.mapRow() which converts snake_case database columns to camelCase TypeScript properties. However, the service's toEnhancedResponse() method expects raw database rows with snake_case properties.
When toEnhancedResponse() tried new Date(row.created_at).toISOString() with row.created_at being undefined (because mapRow converted it to createdAt), it threw RangeError: Invalid time value.
Enhanced repository methods were incorrectly calling mapRow() which
converts snake_case to camelCase, but the service's toEnhancedResponse()
expects raw database rows with snake_case properties. This caused
"Invalid time value" errors when calling new Date(row.created_at).
Fixed methods:
- createEnhanced
- findByVehicleIdEnhanced
- findByUserIdEnhanced
- findByIdEnhanced
- getPreviousLogByOdometer
- getLatestLogForVehicle
- updateEnhanced
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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