fix: Convert DECIMAL columns to numbers in fuel logs API (#49) #50

Merged
egullickson merged 1 commits from issue-49-fix-fuel-display into main 2026-01-18 04:44:37 +00:00
Owner

Summary

  • Fix fuelUnits and costPerUnit displaying as 0.000 due to DECIMAL columns returning as strings from PostgreSQL
  • Add Number() conversion in toEnhancedResponse() for fuel_units and cost_per_unit
  • Fix dynamic updates by invalidating the 'all' query key in mutation handler

Fixes #49

Changes

File Change
backend/src/features/fuel-logs/domain/fuel-logs.service.ts Add Number() conversion for fuelUnits and costPerUnit
frontend/src/features/fuel-logs/hooks/useFuelLogs.tsx Add invalidation for ['fuelLogs', 'all'] query key

Root Cause

PostgreSQL DECIMAL columns are returned as strings by the pg driver. The totalCost field was already converted with Number(), but fuelUnits and costPerUnit were not, causing frontend defensive checks to fail and display 0.000.

Test plan

  • Verify Summary card displays correct total fuel units
  • Verify log entries display correct gallons and price per gallon (e.g., 5.500 @ $3.459)
  • Verify adding a new fuel log immediately updates the Recent Fuel Logs list
  • Run lint and type-check (passed locally)

🤖 Generated with Claude Code

## Summary - Fix fuelUnits and costPerUnit displaying as 0.000 due to DECIMAL columns returning as strings from PostgreSQL - Add `Number()` conversion in `toEnhancedResponse()` for `fuel_units` and `cost_per_unit` - Fix dynamic updates by invalidating the 'all' query key in mutation handler Fixes #49 ## Changes | File | Change | |------|--------| | `backend/src/features/fuel-logs/domain/fuel-logs.service.ts` | Add `Number()` conversion for fuelUnits and costPerUnit | | `frontend/src/features/fuel-logs/hooks/useFuelLogs.tsx` | Add invalidation for `['fuelLogs', 'all']` query key | ## Root Cause PostgreSQL DECIMAL columns are returned as strings by the `pg` driver. The `totalCost` field was already converted with `Number()`, but `fuelUnits` and `costPerUnit` were not, causing frontend defensive checks to fail and display 0.000. ## Test plan - [ ] Verify Summary card displays correct total fuel units - [ ] Verify log entries display correct gallons and price per gallon (e.g., `5.500 @ $3.459`) - [ ] Verify adding a new fuel log immediately updates the Recent Fuel Logs list - [ ] Run lint and type-check (passed locally) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
egullickson added 1 commit 2026-01-18 04:38:19 +00:00
fix: convert DECIMAL columns to numbers in fuel logs API (refs #49)
All checks were successful
Deploy to Staging / Build Images (pull_request) Successful in 4m50s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 38s
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
5c62b6ac96
PostgreSQL DECIMAL columns return as strings from pg driver.
- Add Number() conversion for fuelUnits and costPerUnit in toEnhancedResponse()
- Add query invalidation for 'all' key to fix dynamic updates

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
egullickson merged commit 3ad349c171 into main 2026-01-18 04:44:37 +00:00
egullickson deleted branch issue-49-fix-fuel-display 2026-01-18 04:44:38 +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#50