fix: make order search case-insensitive

Searching "JOHN" or "ord-1001" returned no orders because SQLite instr()
is case-sensitive. Compare lowercased values for order number, customer
name, and email. Adds API regression tests for both cases.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUfxyr6EcRi4EYSX1wLoRh
This commit is contained in:
shawn
2026-09-11 14:54:14 +10:00
co-authored by Claude Sonnet 5
parent 16be44079d
commit 94ebd0733a
2 changed files with 19 additions and 3 deletions
+5 -3
View File
@@ -37,11 +37,13 @@ function toOrderItemDetail(row: {
export async function listOrderSummaries(context: DatabaseContext, query?: string) {
const search = query?.trim();
// Support staff type search terms in any case. instr() is case-sensitive, so compare lowercased
// values; LIKE is avoided because it would treat % and _ in the search text as wildcards.
const filters = search
? or(
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`,
sql`instr(lower(${users.name}), lower(${search})) > 0`,
sql`instr(lower(${users.email}), lower(${search})) > 0`
)
: undefined;