fix: Fuel Logs API 500 error - repository snake_case mismatch (#47) #48

Merged
egullickson merged 2 commits from issue-47-fix-fuel-logs-api into main 2026-01-18 04:33:03 +00:00
Owner

Summary

  • 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.

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

  • Backend type-check passes
  • Backend lint passes
  • CI/CD pipeline passes
  • Verify fuel logs page loads on staging
  • Verify adding fuel log entry works

Fixes #47

## Summary - 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`. ## 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 - [x] Backend type-check passes - [x] Backend lint passes - [ ] CI/CD pipeline passes - [ ] Verify fuel logs page loads on staging - [ ] Verify adding fuel log entry works Fixes #47
egullickson added 1 commit 2026-01-18 04:08:45 +00:00
fix: return raw rows from enhanced repository methods (refs #47)
All checks were successful
Deploy to Staging / Build Images (pull_request) Successful in 2m28s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 29s
Deploy to Staging / Verify Staging (pull_request) Successful in 7s
Deploy to Staging / Notify Staging Ready (pull_request) Successful in 6s
Deploy to Staging / Notify Staging Failure (pull_request) Has been skipped
574acf3e87
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 <noreply@anthropic.com>
egullickson added 1 commit 2026-01-18 04:27:29 +00:00
chore: updates
All checks were successful
Deploy to Staging / Build Images (pull_request) Successful in 3m49s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 29s
Deploy to Staging / Verify Staging (pull_request) Successful in 7s
Deploy to Staging / Notify Staging Ready (pull_request) Successful in 6s
Deploy to Staging / Notify Staging Failure (pull_request) Has been skipped
444abf2255
egullickson merged commit 33c88e7591 into main 2026-01-18 04:33:03 +00:00
egullickson deleted branch issue-47-fix-fuel-logs-api 2026-01-18 04:33:03 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: egullickson/motovaultpro#48