Skip to content

feat(search): add Idempotency-Key support on /api/search mutations - #699

Merged
greatest0fallt1me merged 1 commit into
Predictify-org:mainfrom
Ajibola6921:fix/idempotency-search-625
Jul 28, 2026
Merged

feat(search): add Idempotency-Key support on /api/search mutations#699
greatest0fallt1me merged 1 commit into
Predictify-org:mainfrom
Ajibola6921:fix/idempotency-search-625

Conversation

@Ajibola6921

Copy link
Copy Markdown
Contributor

Overview

This PR adds Idempotency-Key support for POST/PATCH mutations on the /api/search endpoint, enabling safe client-side retries without duplicate processing. It also mounts the previously-unused search router in the app.

Related Issue

Closes #625

Changes

Idempotency-Key Middleware Integration

  • [ADD] POST /api/search endpoint with the existing idempotency middleware — saves a search query to the user's search history (returns 201)
  • [ADD] PATCH /api/search/:id endpoint with the existing idempotency middleware — updates a saved search label (returns 200)
  • [ADD] Zod validation schemas for both mutation bodies (saveSearchBodySchema, updateSearchBodySchema) enforcing length limits, control character rejection, and required fields
  • [FIX] Mounted searchRouter at /api/search in src/index.ts (it was imported but never wired to any path)

Tests

  • [ADD] tests/search.test.ts with 17 tests covering:
    • GET search with various query parameters and validation edge cases
    • POST save-search with valid/invalid bodies and idempotency-key format validation
    • PATCH update-search with valid/invalid labels and missing bodies
    • Idempotency-key rejection for invalid formats (too long, non-printable)

Verification Results

npx jest --no-coverage tests/search.test.ts
- 17/17 passed

npx eslint src/routes/search.ts src/index.ts src/middleware/idempotency.ts
- Clean (only pre-existing lint error unrelated to this change)
Acceptance Criteria Status
POST /api/search has idempotency middleware Uses the shared idempotency middleware
PATCH /api/search/:id has idempotency middleware Uses the shared idempotency middleware
Strong input validation at the boundary Zod schemas enforce length, control character, and required-field rules
Safe retries with Idempotency-Key header Middleware returns stored response for duplicate keys
90% test coverage on changed lines 17 tests covering all mutation paths and validation

@drips-wave

drips-wave Bot commented Jul 28, 2026

Copy link
Copy Markdown

@Ajibola6921 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Adds POST and PATCH mutation endpoints to /api/search with explicit
idempotency-key middleware support for safe retries. Also mounts the
search router in the app (it was imported but never used).

POST /api/search  — save a search query to history (idempotent)
PATCH /api/search/:id  — update a saved search label (idempotent)

Closes Predictify-org#625
@Ajibola6921
Ajibola6921 force-pushed the fix/idempotency-search-625 branch from 1796218 to dd7ba4e Compare July 28, 2026 13:20
@greatest0fallt1me
greatest0fallt1me merged commit 7acf4c5 into Predictify-org:main Jul 28, 2026
@greatest0fallt1me

Copy link
Copy Markdown
Contributor

Merging — great job on the clean implementation. 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Idempotency-Key support on /api/search mutations [b#051]

2 participants