Skip to content

Add API endpoint to export event session votes - #1675

Merged
HugoGresse merged 2 commits into
mainfrom
feat/api-export-event-votes
Jun 14, 2026
Merged

Add API endpoint to export event session votes#1675
HugoGresse merged 2 commits into
mainfrom
feat/api-export-event-votes

Conversation

@HugoGresse

Copy link
Copy Markdown
Owner

What

Adds GET /events/:projectId/votes to the public API — exports every session's votes for an event as JSON.

Reuses the core transformation of scripts/exportAllEventVotes.ts, ported into functions/src/api/services/exportEventVotes.ts:

  • fetch the event's public sessions/speakers JSON (config.jsonUrl),
  • join each session with its projects/{id}/sessionVotes/{sessionId} doc,
  • flatten votes into columns keyed by vote-item name (e.g. "Quality": "Great talk (2)").

The CSV/file IO stays in the script; the API returns { projectId, sessionsCount, sessions[] }.

Auth — both key types, scoped

Accepts either key via the existing authenticateRequest:

  • Event key (ofproj_) → only its own event (request.project.id must match the path).
  • Org key (oforg_) → any event whose organizationId matches the org.

Mismatches return 404 (not 403) so event ids stay non-enumerable.

Hardening vs the script

The script assumed well-formed data; the service guards: missing config.jsonUrl → 400, missing speakers, and vote items that don't map to a question are skipped instead of throwing.

Tests

getVotes.spec.ts — 6 cases:

  • no key → 401
  • project key match → 200 + exported row
  • project key, different event → 404
  • org key, event in org → 200
  • org key, event in another org → 404
  • missing public data URL → 400

Functions build ✓ · lint ✓ · API tests 20/20 ✓

Notes / possible follow-ups

  • Could add ?format=csv later (the row shape is already CSV-ready).
  • The standalone script wasn't refactored to import this service (it lives outside the functions package with its own Firestore init); can unify later if wanted.

🤖 Generated with Claude Code

GET /events/:projectId/votes returns the per-session vote export, reusing
the core transformation of scripts/exportAllEventVotes.ts (fetch the
event's public sessions/speakers JSON, join each session with its
sessionVotes doc, flatten votes into columns keyed by vote-item name).
The CSV/file IO stays in the script; the API returns JSON rows.

Auth accepts either key type, scoped to avoid cross-tenant access:
- event API key (ofproj_): only its own event,
- organization key (oforg_): any event in that organization.
Mismatches return 404 (not 403) so event ids aren't enumerable.

Tested: project key (match/mismatch), org key (in-org/other-org),
missing key, and missing public data URL.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@cypress

cypress Bot commented Jun 14, 2026

Copy link
Copy Markdown

open-feedback    Run #3050

Run Properties:  status check failed Failed #3050  •  git commit 910416d789: Add API endpoint to export event session votes (#1675)
Project open-feedback
Branch Review main
Run status status check failed Failed #3050
Run duration 02m 13s
Commit git commit 910416d789: Add API endpoint to export event session votes (#1675)
Committer Hugo Gresse
View all properties for this run ↗︎

Test results
Tests that failed  Failures 1
Tests that were flaky  Flaky 1
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 13
View all changes introduced in this branch ↗︎

Tests for review

Failed  cypress/e2e/feedback/talk.spec.js • 1 failed test

View Output

Test Artifacts
Single talk > Check that boolean vote does work with multiples votes as the same time as text votes Test Replay Screenshots
Flakiness  cypress/e2e/feedback/talk.spec.js • 1 flaky test

View Output

Test Artifacts
Single talk > Check that text vote does work (post, edit and delete) Test Replay Screenshots

@github-actions

github-actions Bot commented Jun 14, 2026

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit 264e3b8):

https://open-feedback-42--pr1675-feat-api-export-even-0sq33l8v.web.app

(expires Sun, 21 Jun 2026 16:02:05 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 08b588459ed3335bea4061fbe93b8b77635ad43a

@HugoGresse
HugoGresse marked this pull request as ready for review June 14, 2026 15:47
Copilot AI review requested due to automatic review settings June 14, 2026 15:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

Comment thread functions/src/api/services/exportEventVotes.ts
Comment thread functions/src/api/services/exportEventVotes.ts Outdated
Comment thread functions/src/api/services/exportEventVotes.ts Outdated
Comment thread functions/src/api/routes/events/getVotes.ts Outdated
- Default a missing vote `plus` to 0 instead of emitting "(undefined)".
- Convert fetch failures (network error, non-2xx, invalid JSON) into a
  400 with a clear message instead of an opaque 500.
- Fetch session vote docs concurrently (Promise.all) and pre-index vote
  items by id, avoiding sequential awaits and repeated .find() on large
  events.
- Org-key path: a non-existent project and a wrong-org project now return
  the identical 404 "Event not found", so event ids stay non-enumerable.

Tests cover the unified 404, the plus default, and the fetch-error 400.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@HugoGresse
HugoGresse merged commit 910416d into main Jun 14, 2026
10 checks passed
@HugoGresse
HugoGresse deleted the feat/api-export-event-votes branch June 14, 2026 16:09
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.

2 participants