Skip to content

feat: add prediction note, admin role update, trending markets & competition participants endpoints#496

Merged
Olowodarey merged 1 commit intoArena1X:mainfrom
Akanimoh12:feat/backend-prediction-note-admin-role-trending-markets-competition-participants
Mar 30, 2026
Merged

feat: add prediction note, admin role update, trending markets & competition participants endpoints#496
Olowodarey merged 1 commit intoArena1X:mainfrom
Akanimoh12:feat/backend-prediction-note-admin-role-trending-markets-competition-participants

Conversation

@Akanimoh12
Copy link
Copy Markdown
Contributor

Summary

This PR implements four new backend endpoints addressing multiple open issues:

Closes #443
Closes #403
Closes #431
Closes #424


Issue #443 — [Backend] Prediction History - Edit Prediction Note

Endpoint: PATCH /predictions/:id/note

Changes:

  • Added note field (text, nullable) to the Prediction entity
  • Created UpdatePredictionNoteDto with validation (string, max 1000 chars)
  • Implemented updateNote() in PredictionsService with ownership validation — only the prediction owner can update their note
  • Added PATCH :id/note endpoint in PredictionsController with ParseUUIDPipe
  • Included note field in PredictionWithStatus interface and enrichWithStatus() response
  • Created database migration 1775000000000-AddPredictionNoteColumn
  • Added unit tests for successful note update and ownership validation (NotFoundException)

Access: Authenticated users (own predictions only)


Issue #403 — [Backend] Admin User Management - Update User Role

Endpoint: PATCH /admin/users/:id/role

Changes:

  • Created UpdateUserRoleDto with @IsEnum(Role) validation (user | admin)
  • Implemented updateUserRole() in AdminService with:
    • Self-demotion prevention (BadRequestException if admin tries to change own role)
    • User existence validation
    • Audit logging via AnalyticsService.logActivity() with previous/new role details
  • Added PATCH users/:id/role endpoint in AdminController (protected by @Roles(Role.Admin) guard)
  • Added unit tests for role update, self-demotion prevention, and user not found scenarios

Access: Admin only
Validation: Cannot demote yourself


Issue #431 — [Backend] Market Discovery - Trending Markets

Endpoint: GET /markets/trending

Changes:

  • Created TrendingMarketsQueryDto with pagination support (page/limit, max 50)
  • Created TrendingMarketItem and PaginatedTrendingMarketsResponse DTOs
  • Implemented trending algorithm in MarketsService with scoring based on:
    • Participant count (50% weight) — higher participation = more trending
    • Pool size (30% weight) — larger stakes = more activity
    • Time to resolution (20% weight) — markets ending sooner rank higher
  • Added in-memory caching with 15-minute TTL to avoid expensive recalculations
  • Route placed before :id parameterized routes to avoid path conflicts
  • Added unit tests for trending score sorting, pagination, and cache behavior

Access: Public


Issue #424 — [Backend] Competition - Get Participants

Endpoint: GET /competitions/:id/participants

Changes:

  • Created ListParticipantsQueryDto with pagination support (page/limit, max 50)
  • Created ParticipantItem and PaginatedParticipantsResponse DTOs
  • Implemented getParticipants() in CompetitionsService with:
    • Competition existence validation
    • Join with User entity for username/address display
    • Ordered by score (DESC) then join date (ASC) for rankings
  • Added CompetitionParticipant entity to CompetitionsModule imports
  • Added GET :id/participants endpoint in CompetitionsController (Public)
  • Added unit tests for paginated participants and competition not found scenarios

Access: Public


Testing

All existing and new tests pass:

  • 30 test suites, 194 tests — all passing
  • Lint — clean (ESLint with TypeScript strict checks)
  • Build — successful compilation

Files Changed

Area Files
Predictions prediction.entity.ts, predictions.controller.ts, predictions.service.ts, list-my-predictions.dto.ts, update-prediction-note.dto.ts, predictions.service.spec.ts
Admin admin.controller.ts, admin.service.ts, update-user-role.dto.ts, admin.service.spec.ts
Markets markets.controller.ts, markets.service.ts, trending-markets.dto.ts, markets.service.spec.ts
Competitions competitions.controller.ts, competitions.service.ts, competitions.module.ts, list-participants.dto.ts, competitions.service.spec.ts
Migrations 1775000000000-AddPredictionNoteColumn.ts

…tition participants

- Add PATCH /predictions/:id/note endpoint with ownership validation (Arena1X#443)
- Add note field to Prediction entity with migration
- Add PATCH /admin/users/:id/role endpoint with self-demotion prevention (Arena1X#403)
- Log role changes for audit trail
- Add GET /markets/trending endpoint with trending algorithm (Arena1X#431)
- Calculate trending score from participant count, pool size, time to resolution
- Add in-memory caching with 15-minute TTL
- Add GET /competitions/:id/participants endpoint (Arena1X#424)
- Include scores, rankings, and pagination support
- Add comprehensive unit tests for all new features
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
insight-arena-4rll Ready Ready Preview, Comment Mar 30, 2026 0:10am

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 30, 2026

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

@Olowodarey Olowodarey merged commit 8b6cd26 into Arena1X:main Mar 30, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants