améliore l'import (normalisation colonnes)
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user