mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-07 07:55:16 +02:00
feat: check for duplicate phone number in campaign
This commit is contained in:
parent
6f41e91f67
commit
814271e7b1
1 changed files with 30 additions and 0 deletions
|
|
@ -85,6 +85,36 @@ def _validate_source_data(
|
|||
),
|
||||
)
|
||||
|
||||
# Check for duplicate phone numbers
|
||||
seen_phones: dict[str, int] = {} # phone -> first row where it appeared
|
||||
duplicate_rows = []
|
||||
for row_idx, row in enumerate(rows, start=2):
|
||||
if len(row) <= phone_number_idx:
|
||||
continue
|
||||
|
||||
phone_number = row[phone_number_idx].strip()
|
||||
if not phone_number:
|
||||
continue
|
||||
|
||||
if phone_number in seen_phones:
|
||||
duplicate_rows.append(row_idx)
|
||||
else:
|
||||
seen_phones[phone_number] = row_idx
|
||||
|
||||
if duplicate_rows:
|
||||
if len(duplicate_rows) > 5:
|
||||
rows_str = f"{', '.join(map(str, duplicate_rows[:5]))} and {len(duplicate_rows) - 5} more"
|
||||
else:
|
||||
rows_str = ", ".join(map(str, duplicate_rows))
|
||||
|
||||
return ValidationResult(
|
||||
is_valid=False,
|
||||
error=ValidationError(
|
||||
message=f"Duplicate phone numbers found in rows: {rows_str}. Phone numbers in a campaign must be unique.",
|
||||
invalid_rows=duplicate_rows,
|
||||
),
|
||||
)
|
||||
|
||||
return ValidationResult(is_valid=True)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue