Skip to content

fix(customers): normalize formatted phone queries in customer list search - #433

Merged
khaira777 merged 2 commits into
mainfrom
feat/issue-391-formatted-phone-search
Aug 20, 2026
Merged

khaira777 merged 2 commits into
mainfrom
feat/issue-391-formatted-phone-search

Conversation

@khaira777

Copy link
Copy Markdown
Contributor

Intent

Normalize formatted phone queries in the customer list search so admins can find customers by pasted phone numbers without breaking name, email, pagination, sorting, or active filtering.

What Changed

  • Strip non-digit characters from phone-number search queries before matching against phone_digits, so formatted numbers like +1 (555) 123-4567 or 555-123-4567 now find the matching customer
  • Skip the phone_digits LIKE clause entirely when the search contains no digits, preventing false matches on pure text queries
  • Add integration test coverage for formatted phone searches, name/email-only matching, pagination, sorting, and active-customer filtering

Risk Assessment

✅ Low: Minimal, well-scoped change that strips non-digits from the search term before matching against the digits-only phone_digits column, while preserving raw text matching for name/email. The else branch for digit-free queries is a safe optimization that avoids a no-op LIKE against a digits-only column.

Testing

Phone-search integration test (36/36 pass) validates formatted phone normalization against the admin /customers?search= endpoint: stripped digits match phone_digits, while raw text matches name/email; pagination, sort order, and is_active filter preserved.

Evidence: phone-search-integration test run

36/36 passed, 0 failed — formatted phone queries (+1 (555) 123-4567, 555-123-4567, +91 98765-43210) match correctly; name, email, pagination, sorting, active filtering all intact

Integration: customer phone search bridges e164 + legacy + pretty
============================================================
  ✓ search returns 200 for short digits
  ✓ digits "9876543210" matches e164 (got 1)
  ✓ e164 row returned for short query
  ✓ search returns 200 for intl digits
  ✓ intl digits match e164 (got 1)
  ✓ e164 row returned for intl query
  ✓ search returns 200 for inactive digits
  ✓ inactive e164 row excluded by is_active = 1
  ✓ AR digits find ci-ar only (got 1)
  ✓ AR row is ci-ar
  ✓ US short digits "5551234567" find ci-us only after stripping parens (got 1)
  ✓ US pretty-format row matched for short query
  ✓ US intl digits "15551234567" find ci-us only (got 1)
  ✓ US pretty-format row matched for intl query
  ✓ name LIKE branch matches anita (got 3)
  ✓ list filter short query matches e164 (got 1)
  ✓ list returns e164
  ✓ list filter intl query excludes local (got 1)
  ✓ list returns e164 for intl query
  ✓ list filter formatted US query matches ci-us only                    <-- NEW: formatted phone "+1 (555) 123-4567" matches
  ✓ list filter matches US row for formatted international query
  ✓ list filter formatted US local query matches ci-us only             <-- NEW: formatted local "555-123-4567" matches
  ✓ list filter matches US row for formatted local query
  ✓ list filter formatted India query matches ci-e164 only              <-- NEW: formatted intl "+91 98765-43210" matches
  ✓ list filter matches India row for formatted query
  ✓ list filter US short query matches ci-us only (got 1)
  ✓ list filter matches US pretty-format row
  ✓ list filter US intl query matches ci-us only (got 1)
  ✓ list filter matches US pretty-format row for intl query
  ✓ list filter continues matching customer names                       <-- NEW: name search still works
  ✓ name search returns Alice Smith
  ✓ list filter continues matching customer emails                      <-- NEW: email search still works
  ✓ email search returns Alice Smith
  ✓ list filter preserves pagination                                    <-- NEW: pagination intact
  ✓ list filter preserves ascending name sorting
  ✓ list filter preserves is_active = 1 filtering                      <-- NEW: active filtering intact

36/36 passed, 0 failed

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • node tests/run-electron-node-test.cjs tests/phone-search-integration.test.ts
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR fixes customer-list searches so formatted phone numbers are matched using normalized digits while digit-bearing names and emails no longer overmatch phone records.

  • Normalizes phone-like search terms before querying phone_digits.
  • Restricts non-phone-like searches to customer names and emails.
  • Adds integration coverage for formatted phones, mixed text queries, pagination, sorting, and active filtering.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
main/routes/customers.ts The search classification now preserves formatted-phone matching while resolving the previously reported mixed-query overmatch.
tests/phone-search-integration.test.ts Integration coverage verifies formatted phone lookup, digit-bearing name and email behavior, pagination, sorting, and active filtering.

Reviews (2): Last reviewed commit: "fix(customers): avoid phone overmatching..." | Re-trigger Greptile

Comment thread main/routes/customers.ts Resolved
@khaira777
khaira777 enabled auto-merge (squash) August 20, 2026 23:47
@khaira777
khaira777 merged commit e5ddfd3 into main Aug 20, 2026
13 checks passed
@khaira777
khaira777 deleted the feat/issue-391-formatted-phone-search branch August 20, 2026 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant