feat(csv_import): Enhance CSV import functionality with new endpoint and parsing improvements
- 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:
1 parent
36417bfdf3
commit
851018b3b9
6 files changed
+637
-4
No files matched your search
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user