feat(csv-parser): Implement CSV import functionality with mapping and type conversion
- Added permissions for editing and deleting CSV field mappings. - Created type converter for CSV cells to handle various data types. - Implemented database migrations for CSV field mappings and import logs. - Seeded initial system templates for nutrition and activity data imports. - Developed admin endpoints for managing system CSV templates. - Introduced user endpoints for CSV import analysis and mapping retrieval. - Added tests for core CSV parser functionalities, including delimiter detection and value conversion.
This commit is contained in:
1 parent
73963e7140
commit
4a771f6a83
16 files changed
+3252
-1
No files matched your search
@@ -481,4 +481,36 @@ export const api = {
|
||||
|
||||
// Placeholder Metadata Export (v1.0)
|
||||
exportPlaceholdersExtendedJson: () => req('/prompts/placeholders/export-values-extended'),
|
||||
|
||||
// Universal CSV Import (Issue #21)
|
||||
getCsvModules: () => req('/csv/modules'),
|
||||
getCsvLimits: () => req('/csv/limits'),
|
||||
getCsvMappings: (module = null) =>
|
||||
req(module ? `/csv/mappings?module=${encodeURIComponent(module)}` : '/csv/mappings'),
|
||||
copyCsvMapping: (mappingId, body = null) =>
|
||||
req(`/csv/mappings/${mappingId}/copy`, body ? json(body) : { method: 'POST' }),
|
||||
analyzeCsv: async (file, module, delimiter = null) => {
|
||||
const fd = new FormData()
|
||||
fd.append('file', file)
|
||||
fd.append('module', module)
|
||||
if (delimiter) fd.append('delimiter', delimiter)
|
||||
const res = await fetch(BASE + '/csv/analyze', { 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()
|
||||
},
|
||||
adminListCsvTemplates: (module = null) =>
|
||||
req(module ? `/admin/csv-templates?module=${encodeURIComponent(module)}` : '/admin/csv-templates'),
|
||||
adminGetCsvTemplate: (id) => req(`/admin/csv-templates/${id}`),
|
||||
adminCreateCsvTemplate: (d) => req('/admin/csv-templates', json(d)),
|
||||
adminUpdateCsvTemplate: (id, d) => req(`/admin/csv-templates/${id}`, jput(d)),
|
||||
adminDeleteCsvTemplate: (id) => req(`/admin/csv-templates/${id}`, { method: 'DELETE' }),
|
||||
adminGetCsvImportLimits: () => req('/admin/csv-templates/import-limits'),
|
||||
adminPutCsvImportLimits: (d) => req('/admin/csv-templates/import-limits', jput(d)),
|
||||
}
|
||||
Reference in new issue
Block a user