update map convertor - untested
This commit is contained in:
parent
24ce74d61c
commit
87767b07e2
@ -240,15 +240,23 @@ class DataConvertController {
|
|||||||
for (const location of data) {
|
for (const location of data) {
|
||||||
try {
|
try {
|
||||||
// Transform to match locations table structure
|
// 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 = {
|
const locationData = {
|
||||||
'Geo-Location': location['Geo-Location'],
|
'Geo-Location': location['Geo-Location'],
|
||||||
latitude: parseFloat(location.latitude),
|
latitude: parseFloat(location.latitude),
|
||||||
longitude: parseFloat(location.longitude),
|
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',
|
created_by_user: req.session.userEmail || 'csv_import',
|
||||||
last_updated_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
|
// Map CSV fields to NocoDB fields
|
||||||
const fieldMapping = {
|
const fieldMapping = {
|
||||||
'first name': 'First Name',
|
'first name': 'First Name',
|
||||||
@ -294,21 +302,39 @@ class DataConvertController {
|
|||||||
locationData[targetField] = String(level);
|
locationData[targetField] = String(level);
|
||||||
}
|
}
|
||||||
} else if (targetField === 'Notes') {
|
} else if (targetField === 'Notes') {
|
||||||
// Append CSV filename info to existing notes
|
// Build notes with existing content, CSV info, and geocoding info
|
||||||
const existingNotes = location[key] || '';
|
const noteParts = [];
|
||||||
const csvInfo = `Imported from CSV: ${location.csv_filename || 'unknown'}`;
|
|
||||||
locationData[targetField] = existingNotes ?
|
// Add existing notes if present
|
||||||
`${existingNotes} | ${csvInfo}` :
|
if (location[key]) {
|
||||||
csvInfo;
|
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 {
|
} else {
|
||||||
locationData[targetField] = location[key];
|
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']) {
|
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
|
// Create location in NocoDB
|
||||||
@ -321,7 +347,7 @@ class DataConvertController {
|
|||||||
logger.error('Location data:', locationData);
|
logger.error('Location data:', locationData);
|
||||||
results.failed++;
|
results.failed++;
|
||||||
results.errors.push({
|
results.errors.push({
|
||||||
address: location.address || location.Address || location.geocoded_address,
|
address: location.address || location.Address || location.ADDRESS,
|
||||||
error: error.message
|
error: error.message
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user