Skip to content

feat(polls): add GET /api/polls/:pollId with authoritative results - #159

Open
vedant7007 wants to merge 1 commit into
CodePlaygroundHub:mainfrom
vedant7007:feat/poll-results-endpoint
Open

vedant7007 wants to merge 1 commit into
CodePlaygroundHub:mainfrom
vedant7007:feat/poll-results-endpoint

Conversation

@vedant7007

Copy link
Copy Markdown

What & why

Closes #158.

There was no single-poll endpoint, and percentages were computed only client-side (PollBubble.jsx), rounding each option independently — so an even 3-way poll shows 33+33+33 = 99%. This adds an authoritative server-side endpoint.

Changes (backend-only)

  • backend/src/lib/pollResults.js (new, pure) — computePollResults(poll) → { totalVotes, options: [{ _id, text, voteCount, percentage }], leadingOptionId }. Percentages use the largest-remainder (Hamilton) method so they sum to exactly 100 (all 0 when there are no votes). No DB/socket/request — pure.
  • poll.controller.js — getPollById (GET /api/polls/:pollId): 400 invalid id, 404 missing, 403 non-member (reusing isGroupMember), else the poll + results. Mirrors getGroupPolls exactly.
  • poll.routes.js — route registered after GET /groups/:groupId (no path collision).

Testing

  • backend/test/poll/pollResults.test.js — 5 cases (no votes, even 2-way, 3-way summing to 100, 6-way summing to 100, clear leader). npm test → 5/5.
  • npm run lint → 0 errors (my files add none). No new dependency.

Contributing as part of Elite Coders Summer of Code (ECSoC 2026).

New single-poll endpoint returning the poll plus computed results whose
percentages always sum to 100 via largest-remainder (Hamilton) rounding
(the client rounds each independently, so even 3-way polls render 99%).
Core is a pure, unit-tested computePollResults util. Backend-only,
no new dependency.

Closes CodePlaygroundHub#158
@vercel

vercel Bot commented Sep 1, 2026

Copy link
Copy Markdown

@vedant7007 is attempting to deploy a commit to the Akash Santra 's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 55e44bdb-0ae7-4310-b42d-ceb10cae53fc


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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 GET /api/polls/:pollId with authoritative (sum-to-100) results

1 participant