feat: add admin raffle with confetti and top-3/staff exclusion

This commit is contained in:
Lago committed 2026-10-15 21:39:57 +02:00
1 parent 5117a25372
commit 3e2f8ff0ed
14 files changed
+680 -2

No files matched your search

+25
View File
@@ -394,6 +394,31 @@ All are `security definer` so they can read `contacts` / `registrations` /
|---|---|---|
| `_assign_service_session_speakers(p_session_id, p_event_id)` | `integer` | Links **every registered staff member** of the event as a speaker of the given session (`on conflict do nothing`). Returns the number of rows affected. Called by both Sessionize sync RPCs for `service_session` sessions — a service session has no individual speaker, so the whole staff team "owns" it. |
## Raffle
Source: [20261015180640_raffle.sql](../../supabase/migrations/20261015180640_raffle.sql).
The admin **Raffle** view draws eligible attendees one at a time for the active
event. Winner selection is authoritative **server-side** (random), so the client
roulette animation only has to decelerate onto the returned name.
- `get_raffle_pool()` → `contact_email, full_name, points` — the eligible
attendees: non-staff, non-Admin (`is_admin` or `@appe.at`), **not** in the
leaderboard **top 3** (`get_leaderboard() limit 3`), and **not** already drawn
in the current run. Returns `[]` for non-admins (guarded by `is_admin()`).
- `draw_raffle_winner()` → `contact_email, full_name, points, draw_number` —
**admin-only.** Picks one random eligible attendee, records them in
`raffle_draws` with the next sequential `draw_number`, and returns the winner.
Raises `No eligible attendees left to draw` when the pool is empty.
- `reset_raffle()` → `void` — **admin-only.** Deletes the current run's winners
for the active event so a new run can begin.
The `raffle_draws` table is keyed by `(event_id, contact_email)` (so an attendee
can win at most once per run), cascades on event/contact deletion, and is
admin-readable via RLS. All three functions are `security definer` with an empty
`search_path`, revoke execution from `PUBLIC` / `anon`, and grant it back only to
`authenticated` (the admin check is enforced inside each function).
## Error handling
RPCs raise Postgres exceptions with human-readable messages (e.g. `you cannot