feat(api): GET /v1/customer/search — company-scoped substring lookup#64
Merged
Conversation
Search by substring across custCompanyName / custFName / custLName (case-insensitive ILIKE). Common SDK pattern is "user types 'acm' in the customer autocomplete," and the existing GET /v1/customer/bycompany/:id paginated list doesn't help unless the caller already knows the company id AND fetches the whole table to filter client-side. Search closes that gap. Auth shape (deliberately stricter than the existing list endpoint): - missing authKey -> 403 - non-master + companyId mismatching auth scope -> 403 - non-master without companyId -> auto-scope to own - master without companyId -> 400 The "master must specify companyId" requirement is intentional — a global cross-tenant substring search is a footgun (latency on huge tables; accidental data exposure if the master key wasn't authorized to read every tenant's data). Forcing the explicit scope keeps the surface predictable. `q` enforces a 2-char minimum at the zod boundary so a dropdown that fires on every keystroke doesn't full-scan the table on the first letter. Route declared before /:id so express doesn't treat "search" as a customer id and route to getCustomerById. OpenAPI gets the full path entry with parameter docs + the response envelope schema. Tests cover the auth contract (403), zod validation paths (q required, min length, strict() rejects unknown params, limit cap), and route mounting (verifies the search-before-:id ordering). Tests: 32 files / 234 passing + 4 integration skipped (was 31 / 227). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
CryptoJones
added a commit
that referenced
this pull request
May 18, 2026
#68 added /v1/timeentry/export.csv but placed the route AFTER the existing /v1/timeentry/:id block. Express tries patterns top-down, so a GET to /v1/timeentry/export.csv matched the :id route first, the intIdParam validator parsed "export.csv" → NaN → 400 with "expected number". The test that asserts 403 on missing authKey was flaking on this path. The export handler was never reached. Mirrors the search-before-:id ordering #64 used for customer. Added a comment block flagging the rule for future contributors. All four timeentry CRUD routes still resolve correctly — they sit AFTER the literals now, which is the correct order. Suite: 261 / 261 + 4 integration skipped (post-fix). Co-authored-by: Aaron K. Clark <akclark@thenetwerk.net> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
New
GET /v1/customer/searchendpoint. Substring match (ILIKE) acrosscustCompanyName/custFName/custLName, company-scoped via authKey or explicitcompanyId. Closes the gap between the per-id GET and the paginated bycompany list.Stricter auth than the list endpoint — master keys MUST specify
companyId(no global cross-tenant search).qenforces a 2-char minimum so an autocomplete that fires on each keystroke doesn't full-scan.Test plan
Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/