Move properties of phones to the phone, not contact_phone

This makes sense because there will naturally be cases where multiple
districts have the same phone number mapped to different contacts.
This commit is contained in:
Eli Ribble 2026-05-22 20:56:22 +00:00
parent f957dc6982
commit 7b04822a9b
No known key found for this signature in database
14 changed files with 143 additions and 104 deletions

View file

@ -29,7 +29,20 @@ func ContactsForOrganization(ctx context.Context, org_id int32) (results []types
if err != nil {
return results, fmt.Errorf("by contact ids: %w", err)
}
e164s := make([]string, 0)
for _, v := range contact_phones_by_contact_id {
for _, p := range v {
e164s = append(e164s, p.E164)
}
}
phones, err := querycomms.PhonesFromE164s(ctx, txn, e164s)
if err != nil {
return results, fmt.Errorf("phones from e164: %w", err)
}
phones_by_e164 := make(map[string]modelcomms.Phone, len(phones))
for _, p := range phones {
phones_by_e164[p.E164] = p
}
results = make([]types.Contact, 0)
for _, row := range rows {
// Exclude the magic Nidus contact
@ -44,9 +57,10 @@ func ContactsForOrganization(ctx context.Context, org_id int32) (results []types
contact_phones := contact_phones_by_contact_id[int64(row.ID)]
phones := make([]types.Phone, len(contact_phones))
for i, p := range contact_phones {
phone := phones_by_e164[p.E164]
phones[i] = types.Phone{
E164: p.E164,
CanSMS: p.CanSms,
E164: phone.E164,
CanSMS: phone.CanSms,
}
}
if row.Name != "" || len(contact_phones) > 0 || len(contact_emails) > 0 {