améliore l'import (normalisation colonnes)

This commit is contained in:
Yannick Le Duc
2025-09-21 20:47:14 +02:00
parent f9bb1caf32
commit ae753dab4e
3 changed files with 57 additions and 3 deletions

View File

@@ -132,6 +132,55 @@ export function getExpectedColumns(type: 'propositions' | 'participants'): strin
}
}
/**
* Normalise les noms de colonnes pour améliorer la compatibilité
*/
export function normalizeColumnName(columnName: string): string {
if (!columnName) return '';
const normalized = columnName.toLowerCase().trim();
// Mappings pour les colonnes communes
const mappings: { [key: string]: string } = {
'email': 'Email',
'e-mail': 'Email',
'mail': 'Email',
'courriel': 'Email',
'prénom': 'Prénom',
'prenom': 'Prénom',
'firstname': 'Prénom',
'first_name': 'Prénom',
'nom': 'Nom',
'lastname': 'Nom',
'last_name': 'Nom',
'titre': 'Titre',
'title': 'Titre',
'description': 'Description',
'desc': 'Description'
};
return mappings[normalized] || columnName;
}
/**
* Normalise les données parsées pour correspondre aux colonnes attendues
*/
export function normalizeParsedData(data: any[], type: 'propositions' | 'participants'): any[] {
const expectedColumns = getExpectedColumns(type);
return data.map(row => {
const normalizedRow: any = {};
// Normaliser chaque colonne
Object.keys(row).forEach(key => {
const normalizedKey = normalizeColumnName(key);
normalizedRow[normalizedKey] = row[key];
});
return normalizedRow;
});
}
export async function downloadTemplate(type: 'propositions' | 'participants'): Promise<void> {
const columns = getExpectedColumns(type);