fix: make order search case-insensitive #6

Open
aziz_28002 wants to merge 1 commits from fix/order-search-case-insensitive-aziz into master
Collaborator

Summary

Staff searching orders by pasting a customer name in uppercase (e.g. JOHN) got no results, even though a matching order (customer "John Smith") existed. This caused friction when copying customer details from other systems into the search box.

Ticket / Assignment

  • Ticket: Support-reported inconsistent order search behavior (case sensitivity)
  • Assignment: Assignment 1

What changed

  • apps/api/src/orders/order-repository.ts: wrapped both operands of each instr() check (order number, customer name, customer email) in lower(), so the search filter in listOrderSummaries matches regardless of letter case.
  • No route, schema, or frontend changes were needed — the bug was isolated to the repository-layer search filter, consistent with CONTRIBUTING.md's "business rules stay in the repository layer" convention.

How to test

bun run check   # fails only on a pre-existing, unrelated TS error in order-search-assignment-1.test.ts (line 28); reproduces identically on master before this change
bun run test    # 11 pass, 0 fail
bun run build:web

Manual checks:

  • Searched /api/orders?query=JOHN and confirmed ORD-1001 and ORD-1003 (customer John Smith) are returned.
  • Confirmed the pre-existing test order-search-assignment-1.test.ts ("searches orders case-insensitively by customer name") passes, where it previously failed.

Screenshots or recordings

N/A (backend-only change)

Risks / follow-ups

  • lower() in SQLite only folds ASCII case by default; non-ASCII customer names (e.g. accented characters) won't case-fold. Not in scope for this ticket — flagging as a possible follow-up if support sees it.
  • bun run check has a pre-existing TypeScript error in order-search-assignment-1.test.ts (unrelated to this change, reproduces on master) — left untouched to keep this PR scoped to the search bug.

PR checklist

  • change is scoped to one ticket or one small reviewable concern
  • acceptance criteria were checked
  • code follows CONTRIBUTING.md
  • no unrelated refactor is mixed in
  • debug code and temporary logs are removed
  • relevant automated checks were run locally
  • changed behavior was manually tested when needed
  • known risks or follow-ups are called out
## Summary Staff searching orders by pasting a customer name in uppercase (e.g. `JOHN`) got no results, even though a matching order (customer "John Smith") existed. This caused friction when copying customer details from other systems into the search box. ## Ticket / Assignment - Ticket: Support-reported inconsistent order search behavior (case sensitivity) - Assignment: Assignment 1 ## What changed - `apps/api/src/orders/order-repository.ts`: wrapped both operands of each `instr()` check (order number, customer name, customer email) in `lower()`, so the search filter in `listOrderSummaries` matches regardless of letter case. - No route, schema, or frontend changes were needed — the bug was isolated to the repository-layer search filter, consistent with CONTRIBUTING.md's "business rules stay in the repository layer" convention. ## How to test ```bash bun run check # fails only on a pre-existing, unrelated TS error in order-search-assignment-1.test.ts (line 28); reproduces identically on master before this change bun run test # 11 pass, 0 fail bun run build:web ``` Manual checks: - Searched `/api/orders?query=JOHN` and confirmed `ORD-1001` and `ORD-1003` (customer John Smith) are returned. - Confirmed the pre-existing test `order-search-assignment-1.test.ts` ("searches orders case-insensitively by customer name") passes, where it previously failed. ## Screenshots or recordings N/A (backend-only change) ## Risks / follow-ups - `lower()` in SQLite only folds ASCII case by default; non-ASCII customer names (e.g. accented characters) won't case-fold. Not in scope for this ticket — flagging as a possible follow-up if support sees it. - `bun run check` has a pre-existing TypeScript error in `order-search-assignment-1.test.ts` (unrelated to this change, reproduces on master) — left untouched to keep this PR scoped to the search bug. ## PR checklist - [x] change is scoped to one ticket or one small reviewable concern - [x] acceptance criteria were checked - [x] code follows `CONTRIBUTING.md` - [x] no unrelated refactor is mixed in - [x] debug code and temporary logs are removed - [x] relevant automated checks were run locally - [x] changed behavior was manually tested when needed - [x] known risks or follow-ups are called out
aziz_28002 added 1 commit 2026-09-16 16:42:15 +00:00
fix: make order search case-insensitive
Runner Test / test (push) Successful in 16s
Runner Test / test (pull_request) Successful in 14s
a5bbc24ecf
instr() in SQLite compares bytes, so searching for a customer name
in uppercase (e.g. "JOHN") silently missed lowercase-stored matches
like "John". Lowercase both sides of the order number, name, and
email comparisons so search matches regardless of the case staff
paste in.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@@ -42,3 +42,1 @@
sql`instr(${orders.orderNumber}, ${search}) > 0`,
sql`instr(${users.name}, ${search}) > 0`,
sql`instr(${users.email}, ${search}) > 0`
sql`instr(lower(${orders.orderNumber}), lower(${search})) > 0`,
Owner

Should move the lower() to the search above, to avoid casting it 3x here.

Should move the `lower()` to the `search` above, to avoid casting it 3x here.
Owner

Summary needs to be about the PR, not the ticket. Can just link the ticket next time in ticket/assignment section. Otherwise, good job on getting the assignment test to pass.

Summary needs to be about the PR, not the ticket. Can just link the ticket next time in ticket/assignment section. Otherwise, good job on getting the assignment test to pass.
All checks were successful
Runner Test / test (push) Successful in 16s
Runner Test / test (pull_request) Successful in 14s
This pull request has changes conflicting with the target branch.
  • apps/api/src/orders/order-repository.ts
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin fix/order-search-case-insensitive-aziz:fix/order-search-case-insensitive-aziz
git checkout fix/order-search-case-insensitive-aziz
Sign in to join this conversation.
No Reviewers
No labels
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: derrick/ai-wave-02#6