Repository navigation
Closed
Labels
area:backendBackend (Express/SQLite)
Description
Refs: #388
Context
The admin customer management page (/customers) allows searching customers by name, phone, or email via the GET /api/customers?search=... endpoint. Customer phone numbers are stored in canonical E.164 format and indexed via a stored generated column phone_digits containing normalized digits.
Verified Current Behavior
- Route Query (
main/routes/customers.tslines 170-174):if (req.query.search) { const search = `%${req.query.search}%`; query += ' AND (c.name LIKE ? OR c.phone_digits LIKE ? OR c.email LIKE ?)'; params.push(search, search, search); }
- POS Search Comparison (
frontend/src/components/pos/CustomerSearch.tsx): Strips non-digit characters before sending queries to/api/customers-search. - Admin Customer Page (
frontend/src/app/(dashboard)/customers/page.tsx): Sends the raw user input directly toGET /api/customers?search=.... - Existing Helper (
main/lib/phone.tsline 16): Already exportsstripPhoneDigits(input: string): string. - Existing Integration Test (
tests/phone-search-integration.test.tslines 97-116): Currently tests only digit-only inputs (e.g.9876543210,5551234567) against/api/customers?search=, omitting formatted strings.
Problem
When an admin types or pastes a formatted phone number into the search bar (such as +1 (555) 123-4567, 555-123-4567, or +91 98765-43210), the backend executes c.phone_digits LIKE '%+1 (555) 123-4567%'. Because phone_digits contains only raw digits (e.g. 15551234567), the query yields zero results, frustrating users who copy-paste customer phone numbers.
Architectural Decision
- Preserve the original raw query for
c.name LIKE ?andc.email LIKE ?. - Derive a digit-only query using the existing backend helper
stripPhoneDigits(rawQuery)forc.phone_digits LIKE ?. - If the digit-only version is non-empty, include the
phone_digitsmatch branch with the stripped digits. If the query contains no digits (e.g. searching for "Alice"), ensure the phone match branch does not match every row or is skipped cleanly. - Do NOT introduce new regex phone parsing libraries or rewrite the database schema.
Exact Implementation Scope
- Backend Customer List Route (
main/routes/customers.ts):- In
GET /, derive:const rawSearch = String(req.query.search || '').trim(); const digitsSearch = stripPhoneDigits(rawSearch);
- Construct the SQL WHERE clause such that
c.name LIKE ?andc.email LIKE ?use%${rawSearch}%, whilec.phone_digits LIKE ?uses%${digitsSearch}%(whendigitsSearch.length > 0). - Use the existing
stripPhoneDigitshelper frommain/lib/phone.ts.
- In
- Integration Tests (
tests/phone-search-integration.test.ts):- Add test assertions for formatted phone search strings against
GET /api/customers?search=...covering US, India, and international formats (e.g.+1 (555) 123-4567,555-123-4567,+91 98765-43210).
- Add test assertions for formatted phone search strings against
Required Behavior
- Searching
+1 (555) 123-4567matches customer record with phone digits15551234567. - Searching
555-123-4567matches customer record with phone digits15551234567. - Searching
+91 98765-43210matches customer record with phone digits919876543210. - Searching
[email protected]orAlice Smithmatches name and email records without interference. - Pagination, sorting, and
is_active = 1filtering remain fully preserved.
Backward Compatibility / Upgrade Behavior
- No database migration or schema alteration needed.
- Uses existing
phone_digitsstored generated column.
Offline-First Requirements
- Operates 100% locally in SQLite.
Non-Goals / What NOT to Do
- Do NOT alter the database schema or rewrite generated column definitions.
- Do NOT change E.164 storage contracts.
- Do NOT add external fuzzy phone search algorithms.
- Do NOT break name or email search capabilities.
Acceptance Criteria
- Formatted phone queries (
+1 (555) 123-4567,555-123-4567,+91 98765-43210) successfully find matching customers viaGET /api/customers?search=.... - Plain text queries continue searching name and email fields.
- Direct digit queries continue searching as before.
- All existing phone search integration tests in
tests/phone-search-integration.test.tspass.
Verification
npm run lint:backend
npm run test:customer-phone-search
npm run test:phone-search-integration
npm run test:phone
npm testDependencies
- None. Independent backend task.
Relationship to Epic
- Part of Phase 2 — International Data Ergonomics in Epic refactor(regionalization): harden country, regional formatting, and international data boundaries #388.
Metadata
Metadata
Assignees
Labels
area:backendBackend (Express/SQLite)
Activity
khaira777 commentedon Aug 20, 2026
Status update — 2026-08-20
🔄 Implementation complete; validation in progress. Commit
0eb0b2ffcontains the backend fix and regression coverage. The no-mistakes pipeline is currently running its review step; no PR has been opened yet. Next stage: complete the gate, then review the generated PR and CI.khaira777 commentedon Aug 20, 2026
Status update — 2026-08-20
✅ Complete. PR #433 is merged at
e5ddfd3cwith the follow-up mixed name/email digit-search correction included. GitHub CI and Greptile checks are green.