Overview
TheElectionRepository class handles all database operations for elections in the Consensus e-voting platform. It implements the IElectionRepository interface and uses SQLite for data persistence.
Constructor
Optional database instance. If not provided, uses the singleton DatabaseConnection instance.
Methods
save
Persists a new election to the database.The election entity to save to the database.
No return value. Throws an error if the save operation fails.
findById
Retrieves an election by its unique identifier.The unique identifier of the election to retrieve.
Returns the Election entity if found, or null if no election exists with the given ID.
findByStatus
Retrieves all elections with a specific status.The status to filter elections by (DRAFT, ACTIVE, CLOSED).
Array of elections matching the specified status. Returns empty array if no matches found.
findActive
Retrieves all currently active elections (status is ACTIVE and current date is between start and end dates).Array of currently active elections. Returns empty array if no active elections found.
update
Updates an existing election in the database.The election entity with updated values. The electionID must match an existing election.
No return value. Throws an error if the update operation fails.
delete
Deletes an election from the database.The unique identifier of the election to delete.
No return value. Throws an error if the delete operation fails.
findAll
Retrieves all elections from the database.Array of all elections in the database. Returns empty array if no elections exist.
Related Types
Election
The Election entity with the following properties:electionID: string- Unique identifiername: string- Election nameelectionType: ElectionType- Type of election (FPTP or PREFERENTIAL)status: ElectionStatus- Current status (DRAFT, ACTIVE, or CLOSED)startDate: Date- Election start dateendDate: Date- Election end datedescription: string- Election description
ElectionStatus
Enum with values:DRAFT- Election is being preparedACTIVE- Election is currently runningCLOSED- Election has ended