Total Fuel shows 0.00 gallons instead of actual total
Each entry shows 0.000 @ $0.000 instead of {gallons} @ ${pricePerGallon}
Recent Fuel Logs don't update dynamically when adding new entries
Root Cause Analysis
PostgreSQL DECIMAL columns are returned as strings by the pg driver. The backend toEnhancedResponse() method in fuel-logs.service.ts converts total_cost to a number but not fuel_units or cost_per_unit:
// fuel-logs.service.ts:273-295
privatetoEnhancedResponse(row: any,efficiency: number|undefined,unitSystem):EnhancedFuelLogResponse{return{fuelUnits: row.fuel_units,// NOT converted - arrives as string
costPerUnit: row.cost_per_unit,// NOT converted - arrives as string
totalCost: Number(row.total_cost),// Converted - works correctly
// ...
};}
Frontend components have defensive checks that fail for strings:
// FuelStatsCard.tsx and FuelLogsList.tsx
constfuelUnits=typeoflog.fuelUnits==='number'?log.fuelUnits.toFixed(3):'0.000';
Query invalidation may need review for dynamic updates
Steps to Reproduce
Navigate to Fuel Logs page
Observe Summary shows 0.00 gallons for Total Fuel
Observe each log entry shows 0.000 @ $0.000 instead of actual values
Add a new fuel log entry
Observe the Recent Fuel Logs list doesn't update
Expected Behavior
Summary shows correct total gallons (e.g., 14.5 gallons)
Each entry shows {gallons} @ ${pricePerGallon} (e.g., 5.500 @ $3.459)
Recent Fuel Logs updates immediately when adding new entries
Acceptance Criteria
toEnhancedResponse() converts fuel_units and cost_per_unit to numbers using Number()
Summary card displays correct total fuel units
Log entries display correct gallons and price per gallon
Adding a new fuel log immediately updates the Recent Fuel Logs list
All existing tests pass
No TypeScript errors
Technical Notes
The getVehicleStats() method already handles this correctly with Number(r.fuel_units)
The fix should follow the same pattern as totalCost: Number(row.total_cost)
Review useFuelLogs.tsx mutation onSuccess to ensure proper query invalidation
## Summary
The fuel logs screen displays incorrect values:
- **Total Fuel** shows `0.00 gallons` instead of actual total
- **Each entry** shows `0.000 @ $0.000` instead of `{gallons} @ ${pricePerGallon}`
- **Recent Fuel Logs** don't update dynamically when adding new entries
## Root Cause Analysis
PostgreSQL DECIMAL columns are returned as strings by the `pg` driver. The backend `toEnhancedResponse()` method in `fuel-logs.service.ts` converts `total_cost` to a number but not `fuel_units` or `cost_per_unit`:
```typescript
// fuel-logs.service.ts:273-295
private toEnhancedResponse(row: any, efficiency: number | undefined, unitSystem): EnhancedFuelLogResponse {
return {
fuelUnits: row.fuel_units, // NOT converted - arrives as string
costPerUnit: row.cost_per_unit, // NOT converted - arrives as string
totalCost: Number(row.total_cost), // Converted - works correctly
// ...
};
}
```
Frontend components have defensive checks that fail for strings:
```typescript
// FuelStatsCard.tsx and FuelLogsList.tsx
const fuelUnits = typeof log.fuelUnits === 'number' ? log.fuelUnits.toFixed(3) : '0.000';
```
## Affected Files
| File | Issue |
|------|-------|
| `backend/src/features/fuel-logs/domain/fuel-logs.service.ts:273-295` | Missing `Number()` conversion on `fuel_units` and `cost_per_unit` |
| `frontend/src/features/fuel-logs/hooks/useFuelLogs.tsx:46-49` | Query invalidation may need review for dynamic updates |
## Steps to Reproduce
1. Navigate to Fuel Logs page
2. Observe Summary shows `0.00 gallons` for Total Fuel
3. Observe each log entry shows `0.000 @ $0.000` instead of actual values
4. Add a new fuel log entry
5. Observe the Recent Fuel Logs list doesn't update
## Expected Behavior
- Summary shows correct total gallons (e.g., `14.5 gallons`)
- Each entry shows `{gallons} @ ${pricePerGallon}` (e.g., `5.500 @ $3.459`)
- Recent Fuel Logs updates immediately when adding new entries
## Acceptance Criteria
- [ ] `toEnhancedResponse()` converts `fuel_units` and `cost_per_unit` to numbers using `Number()`
- [ ] Summary card displays correct total fuel units
- [ ] Log entries display correct gallons and price per gallon
- [ ] Adding a new fuel log immediately updates the Recent Fuel Logs list
- [ ] All existing tests pass
- [ ] No TypeScript errors
## Technical Notes
- The `getVehicleStats()` method already handles this correctly with `Number(r.fuel_units)`
- The fix should follow the same pattern as `totalCost: Number(row.total_cost)`
- Review `useFuelLogs.tsx` mutation `onSuccess` to ensure proper query invalidation
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
The fuel logs screen displays incorrect values:
0.00 gallonsinstead of actual total0.000 @ $0.000instead of{gallons} @ ${pricePerGallon}Root Cause Analysis
PostgreSQL DECIMAL columns are returned as strings by the
pgdriver. The backendtoEnhancedResponse()method infuel-logs.service.tsconvertstotal_costto a number but notfuel_unitsorcost_per_unit:Frontend components have defensive checks that fail for strings:
Affected Files
backend/src/features/fuel-logs/domain/fuel-logs.service.ts:273-295Number()conversion onfuel_unitsandcost_per_unitfrontend/src/features/fuel-logs/hooks/useFuelLogs.tsx:46-49Steps to Reproduce
0.00 gallonsfor Total Fuel0.000 @ $0.000instead of actual valuesExpected Behavior
14.5 gallons){gallons} @ ${pricePerGallon}(e.g.,5.500 @ $3.459)Acceptance Criteria
toEnhancedResponse()convertsfuel_unitsandcost_per_unitto numbers usingNumber()Technical Notes
getVehicleStats()method already handles this correctly withNumber(r.fuel_units)totalCost: Number(row.total_cost)useFuelLogs.tsxmutationonSuccessto ensure proper query invalidation