Skip to content

feat: add prediction cancel endpoint with refund (#180)#283

Open
CyberXpert607 wants to merge 1 commit into
Predictify-org:mainfrom
CyberXpert607:feature/predictions-cancel
Open

feat: add prediction cancel endpoint with refund (#180)#283
CyberXpert607 wants to merge 1 commit into
Predictify-org:mainfrom
CyberXpert607:feature/predictions-cancel

Conversation

@CyberXpert607

Copy link
Copy Markdown

Summary

Implements #180: Add /api/predictions/:id/cancel endpoint with refund for unresolved predictions.

Changes Made

1. Cancel Endpoint (src/routes/predictions/cancel.ts)

  • ✅ POST /api/predictions/:id/cancel
  • ✅ Validates prediction ownership and market status
  • ✅ Refunds stake to user's balance (immediate credit)
  • ✅ Updates prediction status to 'cancelled'
  • ✅ Structured logging with correlation ID

2. Route Registration (src/routes/predictions.ts)

  • ✅ Imported and registered cancelRouter
  • ✅ Authentication applied via requireAuth middleware

3. Tests (tests/routes/predictions/cancel.test.ts)

  • ✅ Success scenario (cancel + refund)
  • ✅ Non-existent prediction → 404
  • ✅ Market settled → 400
  • ✅ Already cancelled → 400
  • ✅ Authentication required → 401
  • ✅ Coverage ≥90%

4. Error Handling

  • ✅ 400: Market settled or cancelled
  • ✅ 400: Prediction already cancelled
  • ✅ 404: Prediction not found
  • ✅ 401: Unauthorized
  • ✅ 500: Internal server error

Related Issue

Closes #180

Checklist

  • Cancel endpoint implemented
  • Refund logic in place
  • Input validation at boundary
  • Structured logging with correlation ID
  • Tests added and passing (≥90% coverage)
  • Route registered correctly
  • Secure (authentication required)

- Add POST /api/predictions/:id/cancel endpoint
- Validate prediction ownership and market status
- Refund stake to user's balance (immediate credit)
- Add audit logging with correlation ID
- Add comprehensive tests (≥90% coverage)
- Register route in predictions.ts
@drips-wave

drips-wave Bot commented Jul 2, 2026

Copy link
Copy Markdown

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

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 /api/predictions/:id/cancel endpoint with refund

1 participant