From 87767b07e2b4a78452dcd37c74e3b42fcb0c812a Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 2 Sep 2025 21:31:25 -0600 Subject: [PATCH] update map convertor - untested --- map/app/controllers/dataConvertController.js | 46 +++++++++++++++----- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/map/app/controllers/dataConvertController.js b/map/app/controllers/dataConvertController.js index 426b9ca..f391e0f 100644 --- a/map/app/controllers/dataConvertController.js +++ b/map/app/controllers/dataConvertController.js @@ -240,15 +240,23 @@ class DataConvertController { for (const location of data) { try { // Transform to match locations table structure + // Preserve original address, don't overwrite with geocoded address + const originalAddress = location.address || location.Address || location.ADDRESS; + const geocodedAddress = location.geocoded_address; + const locationData = { 'Geo-Location': location['Geo-Location'], latitude: parseFloat(location.latitude), longitude: parseFloat(location.longitude), - Address: location.geocoded_address || location.address || location.Address, + Address: originalAddress, // Always use the original address from CSV created_by_user: req.session.userEmail || 'csv_import', last_updated_by_user: req.session.userEmail || 'csv_import' }; + // Track if geocoded address differs from original + const addressDiffers = geocodedAddress && + geocodedAddress.toLowerCase() !== originalAddress.toLowerCase(); + // Map CSV fields to NocoDB fields const fieldMapping = { 'first name': 'First Name', @@ -294,21 +302,39 @@ class DataConvertController { locationData[targetField] = String(level); } } else if (targetField === 'Notes') { - // Append CSV filename info to existing notes - const existingNotes = location[key] || ''; - const csvInfo = `Imported from CSV: ${location.csv_filename || 'unknown'}`; - locationData[targetField] = existingNotes ? - `${existingNotes} | ${csvInfo}` : - csvInfo; + // Build notes with existing content, CSV info, and geocoding info + const noteParts = []; + + // Add existing notes if present + if (location[key]) { + noteParts.push(location[key]); + } + + // Add CSV import info + noteParts.push(`Imported from CSV: ${location.csv_filename || 'unknown'}`); + + // Add geocoded address if it differs from original + if (addressDiffers) { + noteParts.push(`Geocoded as: ${geocodedAddress}`); + } + + locationData[targetField] = noteParts.join(' | '); } else { locationData[targetField] = location[key]; } } }); - // If no notes field was found in CSV, add the CSV import info + // If no notes field was found in CSV, add the CSV import info and geocoding info if (!locationData['Notes']) { - locationData['Notes'] = `Imported from CSV: ${location.csv_filename || 'unknown'}`; + const noteParts = [`Imported from CSV: ${location.csv_filename || 'unknown'}`]; + + // Add geocoded address if it differs from original + if (addressDiffers) { + noteParts.push(`Geocoded as: ${geocodedAddress}`); + } + + locationData['Notes'] = noteParts.join(' | '); } // Create location in NocoDB @@ -321,7 +347,7 @@ class DataConvertController { logger.error('Location data:', locationData); results.failed++; results.errors.push({ - address: location.address || location.Address || location.geocoded_address, + address: location.address || location.Address || location.ADDRESS, error: error.message }); }