Repository navigation
fix(pos): canonical phone_digits column for customer phone search - #116
Conversation
884f479 to
d31fb45
Compare
…t search
Customer phone search sends digit-only queries against customers.phone,
which is stored in mixed formats — e164 ('+919876543210') for rows created
via the modern country picker and legacy local ('9876543210') for older
rows. Plain LIKE can't bridge the leading '+' gap.
Add a STORED generated phone_digits column on customers (digits-only by
construction) via migration v22. Update both search SQL locations to use
the canonical column: /api/customers-search (POS) and /api/customers
?search= (admin list). Drop the unused /api/customers/search route that
had zero callers.
Tests: a unit assertion over the SQL+generated column, an Express-level
integration test that hits both endpoints with a mixed-format seed set,
and schema-version bumps in first-run-setup and database-tools-api.
d31fb45 to
10b4f4b
Compare
|
Thanks for this, clean approach with the generated column. One bug needs fixing before merge: Missing The migration strips -- Current (4 REPLACEs): -- Should be (5 REPLACEs): Same issue applies to any phone entered as Test gap
Formats like |
REPLACE chain missed ) and ., so US-format phones (+1 (555) 123-4567, +1.555.123.4567) produced non-matching phone_digits like 1555)1234567. Frontend already strips all non-digits via /\D/g, so the column must match. Adds a 6th REPLACE for . while the line is in hand. Test gap filled in customer-phone-search and phone-search-integration suites. Addresses review feedback on PR FreeOpenSourcePOS#116.
|
@khaira777 good catch. Fixed in I'm still defaulting to my LATAM phone conventions in my head, I'll keep more global formats in mind from here. Thanks for catching what I missed. |
Override http-cache-semantics to ^4.3.0, katex to ^0.18.2 and smol-toml to ^1.9.0 so the resolved tree clears Dependabot alerts #110, #115 and #116 (CVE-2026-93748, CVE-2026-103923, GHSA-r4xh-jqrq-34v2). All three arrive only through dev tooling (the electron-builder download path and markdownlint-cli2) and none ship in the desktop package or the runtime servers. Effect on FloCafe is limited to npm run docs:check and packaging; the katex jump stays inside 0.18.x to keep the range micromark-extension-math expects. sprintf-js (alert #117) has no patched release upstream, so it is left for a Dependabot dismissal.
Problem
POS CustomerSearch and the admin Customers page filter customers by phone,
sending digit-only queries (
CustomerSearch.digitsOnly).customers.phoneis stored in mixed formats:
+919876543210) — rows from the modern country picker9876543210) — rows from before the i18n work+91 987-654-3210) — manual data entryPlain
phone LIKE ?can'''t bridge the leading+: searching919876543210(country code without+) misses the e164 row entirely.Fix
A STORED generated column on
customers:phonestays untouched, so printers and CRM code keep their e164 input.Search hits the canonical form:
phone_digits LIKE ?bridges everystorage format against any digit-only query.
Changes
main/db.ts— migration v22 addsphone_digits(guarded for retry).main/routes/index.ts:85—/api/customers-searchusesphone_digits LIKE ?.main/routes/customers.ts:56—/api/customers?search=filter usesphone_digits LIKE ?.main/routes/customers.ts— dropped the unused/api/customers/searchroute (zero callers, leftover from a half-finished REST migration).tests/customer-phone-search.test.ts— unit coverage of the SQL pattern + generated column.tests/phone-search-integration.test.ts— boots real Express viaregisterRoutes, hits both endpoints across all format combinations.tests/{first-run-setup,database-tools-api}.test.ts— schema-version assertions bumped to 22.Migration
ALTER TABLE ADD COLUMNonly. STORED generation fills existing rows ondemand. The
getColumnsguard keeps retry from crashing onduplicate-column if a v22 transaction fails before
user_versionisbumped.
Test
npm test— full suite passes.test:phone-search-integrationcoversthe same scenarios I verified by hand against a running backend (mixed
seeds, short digits, intl digits, inactive, name LIKE).