Elections
How staff publish a ballot, how a student casts one vote per position, and every refusal on the way.
| Who | API prefix | Gates | Hub screens |
|---|---|---|---|
| Staff | elections, elections/:electionId/positions | User type staff, Feature.ELECTIONS, an election permission per route | /staff-hub/campus/$campusId/elections |
| Student | student/elections | User type student, Feature.ELECTIONS, no permission decorator | /student/elections |
Writes also need the election's campus year to be unlocked. Paths start with /api/v1; every route is in the route reference.
Setting up and publishing
Create. POST /elections (createElection) stores a draft. isAnonymous defaults to false. The year must be current or future and unlocked, and endsAt must be after startsAt.
Add positions and candidates while it's a draft. A position with no streamIds is open to the whole campus year; with streams, only those streams can vote. A candidate must be actively enrolled in the election's campus year.
Publish. POST /elections/:id/publish (publishElection, update) sets published and publishedAt.
Close. POST /elections/:id/close (closeElection) sets closed and closedAt, whatever endsAt says.
Release results. POST /elections/:id/release-results (releaseElectionResults) sets resultsReleasedAt. Status stays closed. There is no un-release.
Election refusals
| When | Message |
|---|---|
| Create with a backwards window | endsAt must be after startsAt |
| Publish a non-draft | Only draft elections can be published |
Publish after endsAt | Voting window has already ended |
| Publish with no positions | Add at least one position before publishing |
| Publish with an empty position | Every position needs at least one candidate before publishing |
| Close a non-published election | Only published elections can be closed |
| Release before closing | Close the election before releasing results |
| Release twice | Results already released |
Patch a published election other than endsAt | A published election only allows extending endsAt |
Move endsAt earlier | endsAt can only be extended; close the election to end voting early |
| Edit a closed election | Closed elections cannot be edited |
| Delete a non-draft | Only draft elections can be deleted (drafts are soft-deleted) |
| Tallies on a draft | Draft elections have no tallies |
| Unknown id | Election not found |
Position and candidate refusals
All of these routes need the election to be a draft (Only draft elections can be edited).
| Route | When | Message |
|---|---|---|
createElectionPosition | Name already used in this election | A position with this name already exists in this election (409) |
createElectionPosition, updateElectionPosition | A stream id doesn't exist | One or more streams do not exist |
| A stream's class is on another campus | Stream does not belong to this campus | |
updateElectionPosition, candidate PATCH | Body changes nothing | No changes provided |
| Position routes | Position missing or on another election | Position not found |
addElectionCandidate | No such enrollment | Enrollment not found |
Enrollment not active | Candidate enrollment is not active | |
| Another campus or year | Candidate must be actively enrolled in this election's campus year | |
| Already a candidate here | This student is already a candidate for this position (409) | |
| Candidate routes | Candidate on another position | Candidate not found |
Deleting a position or candidate is a soft delete. Sending streamIds on update replaces the targeting.
Casting a vote
List. GET /student/elections (listMyElections) returns published elections whose window contains now, across the student's active enrollments.
Open the ballot. GET /student/elections/:electionId/ballot (getMyBallot) returns positions with hasVoted and isOpen. Drafts are Election not found; closed ones come back with isOpen false. Anonymous elections omit votedCandidateId.
Vote. POST /student/elections/:electionId/positions/:positionId/vote (castElectionVote) with { "candidateId" }. The voter receipt (election_position_voter) and the ballot row are written in one transaction; an anonymous ballot stores voterEnrollmentId as null.
| When | Message |
|---|---|
| No student profile | Student profile not found |
| No active enrollment for the election's campus year | You are not enrolled for this election |
| Election missing or draft | Election not found |
| Not published, or outside the window | Voting is not open for this election |
| Position missing or on another election | Position not found |
| Position limited to streams that exclude the student | This position is not open to your stream |
| Candidate not on that position | Candidate does not belong to this position |
Already voted, including a unique-violation race (23505) | You have already voted for this position |
The audit entry records that a vote was cast but not the response, so the chosen candidate is not in the audit snapshot.
Results. GET /student/elections/results lists elections with resultsReleasedAt set; GET /student/elections/:electionId/results throws Results are not available until then. Counts are ballot rows per candidate, with no voter names.
Hub screens
| Screen | Route | What it does |
|---|---|---|
| Staff list | staff-hub/campus/$campusId/elections | Elections for the viewing year; create surface; "No elections this year" when empty |
| Staff election | .../elections/$electionId | Edit, Publish, Close, Release results, Extend close time, Delete draft, add positions |
| Staff position and candidate | .../positions/$positionId, .../candidates/$candidateId | Manage candidates; remove a candidate |
| Staff tallies | .../elections/$electionId/tallies | Counts per candidate |
| Student list | student/elections | Open elections with voted count; released ones link to results |
| Student ballot | student/elections/$electionId | Open or Closed, Secret or Open ballot; each position shows Voted, To vote or Missed |
| Student position | .../positions/$positionId | Pick a candidate, press "Cast vote"; a secret vote shows "Vote recorded" without a name |
| Student results | student/elections/$electionId/results | Released counts; "Results unavailable" otherwise |
The old student candidate URL (.../candidates/$candidateId) now redirects to the position screen.
Device pairing
How a staff member pairs a phone to the Hub, how the phone's session is checked, and how a phone sends a student photo, a staff profile photo, or library scans.
Analytics
Read-only counts behind one controller. Each route hands off to the service that owns the data, and every count runs on a school-scoped repository.