Class: Decidim::Elections::TrusteeZone::UpdateElectionBulletinBoardStatus

Inherits:
Rectify::Command
  • Object
show all
Defined in:
decidim-elections/app/commands/decidim/elections/trustee_zone/update_election_bulletin_board_status.rb

Overview

This command updates the election status if it got changed

Instance Method Summary collapse

Constructor Details

#initialize(election, required_status) ⇒ UpdateElectionBulletinBoardStatus

Public: Initializes the command.

status - The actual election status


11
12
13
14
# File 'decidim-elections/app/commands/decidim/elections/trustee_zone/update_election_bulletin_board_status.rb', line 11

def initialize(election, required_status)
  @election = election
  @required_status = required_status
end

Instance Method Details

#callObject

Update the election if status got changed.

Broadcasts :ok if successful, :invalid otherwise.


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'decidim-elections/app/commands/decidim/elections/trustee_zone/update_election_bulletin_board_status.rb', line 19

def call
  return broadcast(:ok, election) if election.bb_status.to_sym != required_status.to_sym

  transaction do
    election.create_bb_closure!
    update_election_status!

    if election.bb_tally_ended?
      fetch_election_results
      store_verifiable_results
    end
  end

  broadcast(:ok, election)
end