fix(export): CSV should export date | time | brand name | cost #
Area: Dashboard · Export · server/utils/csv.ts / server/utils/export.ts
Type: bug / enhancement
Priority: p1
Summary #
The dashboard Export button currently exports the raw DB table. It should return a human-readable CSV with columns date | time | brand name | cost.
Current behavior #
POST /api/v2/cigs/export(andGET /api/v2/cigs/export) usesbuildCigCsvinserver/utils/csv.ts:19:id,timestamp,date,cig_type_idserver/utils/export.ts:mapCigRowsToExportDatamaps rows to{ id, timestamp: ms, date: ISO, cigTypeId }— no brand resolution, no cost, date+time collapsed to a single ISO string.pages/dashboard.vue:exportData()just blobs the response. No column mapping on the frontend.fetchExportCurrency()is available but never used for the CSV.
Expected behavior #
CSV header must be exactly:
date,time,brand name,cost
Row example:
2025-09-13,14:32,Marlboro,€0.30
Rules:
- date — local
YYYY-MM-DDderived fromcig.timestamp - time — local
HH:mm(24h) derived fromcig.timestamp - brand name — resolved via
cigTypes.name(cigs.cigTypeId -> cigTypes.id). Empty string ifnull/ deleted type. RFC4180-quoted if it contains,or"(reusecsvEscape). - cost —
cigTypes.pricePerUnitformatted to 2 decimals with user currency symbol (fetchExportCurrency()/getSymbol()— EUR default). If no type/price, empty or0.00(decide and document). Must not double-count source-attributed cost — per-cig type pricing takes precedence (seeserver/utils/stats/cost.ts:attributedCost). - Keep existing
?format=jsonpath untouched. - Keep RFC4180 quoting for all fields (already handles
"/\n/,/=). - Range / filtering should respect existing
resolveExportRange()logic (default 30-day window,range=customwithfrom/to).
Files to touch #
server/utils/csv.ts— change header + row mappingserver/utils/export.ts— add brand+cost resolution (joincigTypes), addformatDate/formatTimehelpers, updateCigExportRow/CigExportDataRowserver/api/v2/cigs/export.post.ts— pass currency/types into CSV builder if neededpages/dashboard.vue— no change needed unless filename/headers changetests/integration/export.test.ts— update expectations
Acceptance criteria #
How to test #
- Create 2 cig types (e.g. Marlboro €0.30, Camel €0.25) in Settings.
- Log cigs with each type + one without type.
- Click Export on dashboard → open CSV → verify 4 columns, correct local date/time, brand, cost.
curl -H "Authorization: Bearer …" -X POST /api/v2/cigs/export?format=csv→ inspect header.