Overview
TheVoterRepository class handles all database operations for voters in the Consensus e-voting platform. It implements the IVoterRepository interface and uses SQLite for data persistence.
Constructor
Optional database instance. If not provided, uses the singleton DatabaseConnection instance.
Methods
save
Persists a new voter to the database.The voter entity to save to the database.
No return value. Throws an error if the save operation fails.
findById
Retrieves a voter by their unique identifier.The unique identifier of the voter to retrieve.
Returns the Voter entity if found, or null if no voter exists with the given ID.
findByEmail
Retrieves a voter by their email address.The email address of the voter to retrieve.
Returns the Voter entity if found, or null if no voter exists with the given email.
update
Updates an existing voter in the database.The voter entity with updated values. The voterID must match an existing voter.
No return value. Throws an error if the update operation fails.
delete
Deletes a voter from the database.The unique identifier of the voter to delete.
No return value. Throws an error if the delete operation fails.
findAll
Retrieves all voters from the database.Array of all voters in the database. Returns empty array if no voters exist.
Related Types
Voter
The Voter entity with the following properties:voterID: string- Unique identifiername: string- Voter’s full nameemail: string- Voter’s email addresspasswordHash: string- Hashed password for authenticationregistrationStatus: RegistrationStatus- Current registration statusregistrationDate: Date- Date when the voter registered
RegistrationStatus
Enum with values:PENDING- Registration is awaiting approvalAPPROVED- Voter is approved and can voteSUSPENDED- Voter account is suspended