Compare commits
2 Commits
e78902d79f
...
3f771bf7b0
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f771bf7b0 | |||
|
|
f1179ddc09 |
@@ -138,35 +138,64 @@
|
||||
|
||||
if (rows.length === 0) throw new Error('No data found in sheet');
|
||||
|
||||
// Extract participant data based on column mapping
|
||||
const names: string[] = [];
|
||||
const surnames: string[] = [];
|
||||
const emails: string[] = [];
|
||||
// --- Start of new logic to handle duplicates ---
|
||||
|
||||
// Skip header row (start from index 1)
|
||||
// First, extract all potential participants from the sheet
|
||||
const potentialParticipants = [];
|
||||
for (let i = 1; i < rows.length; i++) {
|
||||
const row = rows[i];
|
||||
if (row.length > 0) {
|
||||
const name = row[event.name_column - 1] || '';
|
||||
const surname = row[event.surname_column - 1] || '';
|
||||
const email = row[event.email_column - 1] || '';
|
||||
const email = (row[event.email_column - 1] || '').trim();
|
||||
const confirmation = row[event.confirmation_column - 1] || '';
|
||||
|
||||
// Only add if the row has meaningful data (not all empty) AND confirmation is TRUE
|
||||
const isConfirmed =
|
||||
confirmation.toString().toLowerCase() === 'true' ||
|
||||
confirmation.toString().toLowerCase() === 'yes' ||
|
||||
confirmation === '1' ||
|
||||
confirmation === 'x';
|
||||
|
||||
if ((name.trim() || surname.trim() || email.trim()) && isConfirmed) {
|
||||
names.push(name.trim());
|
||||
surnames.push(surname.trim());
|
||||
emails.push(email.trim());
|
||||
if ((name.trim() || surname.trim() || email) && isConfirmed) {
|
||||
potentialParticipants.push({ name: name.trim(), surname: surname.trim(), email });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create a map to count occurrences of each unique participant combination
|
||||
const participantCounts = new Map<string, number>();
|
||||
for (const p of potentialParticipants) {
|
||||
const key = `${p.name}|${p.surname}|${p.email}`.toLowerCase(); // Create a unique key
|
||||
participantCounts.set(key, (participantCounts.get(key) || 0) + 1);
|
||||
}
|
||||
|
||||
// Create final arrays, modifying duplicate surnames to be unique
|
||||
const names: string[] = [];
|
||||
const surnames: string[] = [];
|
||||
const emails: string[] = [];
|
||||
const processedParticipants = new Map<string, number>();
|
||||
|
||||
for (const p of potentialParticipants) {
|
||||
const key = `${p.name}|${p.surname}|${p.email}`.toLowerCase();
|
||||
let finalSurname = p.surname;
|
||||
|
||||
// If this participant is a duplicate
|
||||
if (participantCounts.get(key)! > 1) {
|
||||
const count = (processedParticipants.get(key) || 0) + 1;
|
||||
processedParticipants.set(key, count);
|
||||
|
||||
// If it's not the first occurrence, append a counter to the surname
|
||||
if (count > 1) {
|
||||
finalSurname = `${p.surname} (${count})`;
|
||||
}
|
||||
}
|
||||
|
||||
names.push(p.name);
|
||||
surnames.push(finalSurname);
|
||||
emails.push(p.email); // Keep the original email
|
||||
}
|
||||
// --- End of new logic ---
|
||||
|
||||
// Call database function to add participants
|
||||
const { error: syncError } = await data.supabase.rpc('participants_add_bulk', {
|
||||
p_event: eventId,
|
||||
|
||||
Reference in New Issue
Block a user