wishan / docs/DRAW_REVEAL_FEATURE.md
Draw Winner Reveal Feature - Implementation Details
A mobile app for buying asset shares
Draw Winner Reveal Feature - Implementation Details
Overview
This document details the implementation of the draw winner reveal countdown feature.
Feature Requirements (from issue)
- Add a new status
revealedaftercompleted - Transition from
completedtorevealedvia cron function - Admin inputs reveal date/time when completing draw
- Return winner details to admin when selected
- Return winning ticket number to mobile only when revealed
- Add admin view for winner details
- For completed draws, return reveal date to mobile
- For revealed draws, return winner ticket to mobile
Implementation Details
Database Changes
- Schema: Added
revealedenum value andreveal_atcolumn - Queries: Added query to fetch completed draws ready for reveal
- Query: Added query to update status and reveal_at together
Backend Services
- CompleteDraw(): Now accepts optional
revealAt *time.Timeparameter - RevealDraw(): New method to transition draw to revealed status
- ProcessCompletedDrawsReadyForReveal(): Cron function to auto-reveal draws
API Endpoints
Admin
-
PUT /admin/draws/:id/status- Complete draw with reveal datePOST body: { "action": "complete", "reveal_at": "2026-02-25T10:00:00Z" } -
GET /admin/draws/:id/winner- Get winner details (new endpoint)Response: { "id", "key", "name", "dateOfBirth", "email", "ticketId" } -
POST /admin/draws/:id/select- Now returns winner in response
Mobile
GET /mobile/draws/:id- Includesreveal_atfor completed,winner_ticket_idfor revealedGET /mobile/draws/:id/winner- Returns 403 if not revealed, winner if revealed
Cron Jobs
- process_draw_winner_reveal_schedule: Runs every minute to reveal completed draws
Frontend Components
- CompleteDrawDialog: Date/time picker for setting reveal time
- WinnerDetailsDialog: Display winner information for admin
Status Transition Matrix
| Current Status | Allowed Actions | Next Status |
|---|---|---|
| pending | activate, cancel | active, cancelled |
| active | (automatic when sold out) | selected |
| selected | complete (with reveal date) | completed |
| completed | (automatic at reveal time) | revealed |
| cancelled | none | - |
| revealed | none | - |
Data Visibility
Admin Access
- selected/completed/revealed: Full winner details (user info + ticket ID)
Mobile Access
- selected: No winner information
- completed: Reveal date only (countdown)
- revealed: Winning ticket number only
Security Considerations
- Authorization checks on all endpoints
- Parameterized SQL queries
- Status validation before transitions
- Access control based on reveal status
- No vulnerabilities introduced
See SECURITY_SUMMARY.md for detailed security analysis.
Testing
See TESTING.md for comprehensive testing guide.
Database Schema
The database schema in api/common/infra/database/schema/public.sql includes:
revealedvalue in thedraw_statusenumreveal_at timestamptzcolumn in thedrawstable
These changes are part of the base schema and will be automatically applied when the database is initialized.