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:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user