Overview
TheVoterService handles all business logic related to voter management in the Consensus e-voting platform. It manages voter registration, approval workflows, profile updates, and account deletion (GDPR compliance).
Constructor
Repository for voter data persistence
Methods
registerVoter
Registers a new voter in the system.Voter registration dataVoterRegistrationDTO:
name: string- Voter’s full nameemail: string- Voter’s email address (must be unique)password: string- Password (minimum 8 characters)
Whether to automatically approve the voter (sets status to APPROVED instead of PENDING)
The newly created voter entity with PENDING or APPROVED status
"Email already registered"- Email address is already in use"Invalid email format"- Email does not match valid format"Password must be at least 8 characters"- Password too short
getVoterById
Retrieves a voter by their ID.ID of the voter to retrieve
The voter entity if found, otherwise null
getVoterByEmail
Retrieves a voter by their email address (used for login).Email address of the voter
The voter entity if found, otherwise null
approveVoter
Approves a pending voter registration.ID of the voter to approve
"Voter not found"- Invalid voter ID
- Changes voter’s registration status to APPROVED
- Only approved voters can cast votes
rejectVoter
Rejects a pending voter registration.ID of the voter to reject
"Voter not found"- Invalid voter ID
- Changes voter’s registration status to REJECTED
- Rejected voters cannot cast votes
getAllVoters
Retrieves all registered voters.Array of all voter entities
updateVoter
Updates a voter’s profile information.ID of the voter to update
Object containing fields to update:
name?: string- New nameemail?: string- New email (must be unique and valid)passwordHash?: string- New password hash
The updated voter entity
"Voter not found"- Invalid voter ID"Email already registered"- New email is already in use"Invalid email format"- New email does not match valid format
- Only provided fields are updated
- Email uniqueness is validated when changing email
- Email format is validated when changing email
deleteVoter
Deletes a voter account (GDPR compliance).ID of the voter to delete
"Voter not found"- Invalid voter ID
- Permanently removes voter data from the system
- Supports GDPR “right to be forgotten” compliance
- Vote anonymity ensures ballots remain valid after deletion
Related Types
RegistrationStatus
Enum representing voter registration states:PENDING- Registration submitted, awaiting approvalAPPROVED- Registration approved, can voteREJECTED- Registration rejected, cannot vote
Validation Rules
Email Format
Email addresses must match the pattern:^[^\s@]+@[^\s@]+\.[^\s@]+$
Valid examples:
Invalid examples:
invalid(no @ symbol)user@domain(no TLD)user @example.com(contains spaces)
Password Requirements
- Minimum length: 8 characters
- No maximum length enforced
- Passwords are stored as hashes in production