Skip to content

feat: admin force-resolve endpoint#532

Merged
greatest0fallt1me merged 1 commit into
Predictify-org:mainfrom
muffti123:feature/admin-force-resolve
Jul 26, 2026
Merged

feat: admin force-resolve endpoint#532
greatest0fallt1me merged 1 commit into
Predictify-org:mainfrom
muffti123:feature/admin-force-resolve

Conversation

@muffti123

Copy link
Copy Markdown
Contributor

Summary

Adds a new admin-only force-resolve endpoint at POST /api/admin/force-resolve/:id that allows admins to atomically resolve a stuck market (one past its resolution deadline that hasn't been resolved via the normal oracle path). The endpoint is fully compatible with the existing Idempotency-Key middleware applied globally to all POST mutations.

Closes #179

Changes

New files

  • src/routes/admin/force-resolve.ts — Route handler implementing:

    • requireAdmin JWT guard (403 on missing/invalid token)
    • Zod body validation (winningOutcome: string.min(1)) (422)
    • Market existence check (404)
    • Idempotency guard — skips if already forceFinalized or status === resolved (409)
    • Deadline guard — rejects if resolutionTime is in the future (422)
    • Atomic transaction: updates market + writes marketAuditLog entry with action: force_resolve
    • Structured logging with correlationId via getRequestId()
    • Returns { data: { marketId, winningOutcome, forceResolved: true } }
  • tests/adminForceResolve.test.ts — 13 tests covering:

    • Auth guards (missing header, non-admin JWT, wrong secret)
    • Input validation (missing/empty winningOutcome)
    • Market eligibility (not found, already force-finalized, already resolved via normal path, future deadline)
    • Successful resolution with transaction verification (update + audit log)
    • Error envelope with correlationId propagation

Modified files

File Change
src/index.ts Mounts forceResolveRouter at /api/admin/force-resolve
src/openapi/registry.ts Documents the endpoint with ForceResolveResponse schema and all response codes
scripts/check-openapi.ts Adds POST /api/admin/force-resolve/{id} to expected routes
openapi.yaml Auto-regenerated to include the new endpoint

Verification

  • Tests: 13/13 pass on adminForceResolve.test.ts
  • Lint: Clean
  • Coverage: 97.29% lines, 100% functions on new code
  • No regressions — all other admin test suites continue to pass/fail as before (pre-existing failures unchanged)

API

POST /api/admin/force-resolve/:id
Authorization: Bearer <admin-jwt>
Idempotency-Key: <optional-key>
Content-Type: application/json

{ "winningOutcome": "yes" }

Responses

Status Description
200 Market force-resolved successfully
400 Validation error — missing/invalid winningOutcome
403 Forbidden — missing or invalid admin JWT
404 Market not found
409 Market already resolved or force-finalized
422 Market has not yet reached its resolution deadline

Implement admin-only force-resolve endpoint at POST /api/admin/force-resolve/:id
with Idempotency-Key support and comprehensive test coverage.
@drips-wave

drips-wave Bot commented Jul 26, 2026

Copy link
Copy Markdown

@muffti123 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

@greatest0fallt1me
greatest0fallt1me merged commit 1ce615b into Predictify-org:main Jul 26, 2026
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 idempotent admin force-resolve endpoint

2 participants