update map convertor - untested
This commit is contained in:
parent
24ce74d61c
commit
87767b07e2
@ -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
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user