feat(csv_import): Enhance CSV import functionality with new endpoint and parsing improvements
Deploy Development / deploy (push) Successful in 52s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 15s

- Updated version for csv_import to 0.2.0, reflecting new features.
- Implemented a new POST endpoint for universal CSV import, supporting nutrition, weight, and blood pressure modules.
- Added CSV parsing function to yield rows as dictionaries for easier data handling.
- Enhanced error handling and logging for import operations.
- Introduced tests for the new CSV parsing functionality to ensure reliability.
This commit is contained in:
Lars committed 2026-04-10 06:03:21 +02:00
1 parent 36417bfdf3
commit 851018b3b9
6 files changed
+637 -4

No files matched your search

+16
View File
@@ -489,6 +489,22 @@ export const api = {
req(module ? `/csv/mappings?module=${encodeURIComponent(module)}` : '/csv/mappings'),
copyCsvMapping: (mappingId, body = null) =>
req(`/csv/mappings/${mappingId}/copy`, body ? json(body) : { method: 'POST' }),
importCsv: async (file, module, mappingId) => {
const fd = new FormData()
fd.append('file', file)
fd.append('module', module)
fd.append('mapping_id', String(mappingId))
const res = await fetch(BASE + '/csv/import', { method: 'POST', headers: hdrs(), body: fd })
if (!res.ok) {
const errText = await res.text()
let parsed = null
try {
parsed = JSON.parse(errText)
} catch { /* ignore */ }
throw new Error(formatFastApiDetail(parsed?.detail, errText.trim() || `HTTP ${res.status}`))
}
return res.json()
},
analyzeCsv: async (file, module, delimiter = null) => {
const fd = new FormData()
fd.append('file', file)