Sha256: 7fde02fc79340dbc492c4904b35891586ba23b0ccde2ef76b121e4385d576178

Contents?: true

Size: 1.59 KB

Versions: 19

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

module Decidim
  module Votings
    module Census
      module Admin
        # A command with the business logic to create the datum for a
        # dataset row.
        class CreateDatum < Rectify::Command
          def initialize(form, dataset)
            @form = form
            @dataset = dataset
          end

          # Executes the command. Broadcast this events:
          # - :ok when everything is valid
          # - :invalid when the form wasn't valid and couldn't proceed-
          #
          # Returns nothing.
          def call
            return broadcast(:invalid) unless form.valid?

            create_census_datum!
            broadcast(:ok)
          end

          attr_reader :form, :dataset

          def create_census_datum!
            attributes = {
              hashed_in_person_data: form.hashed_in_person_data,
              hashed_check_data: form.hashed_check_data,

              full_name: form.full_name,
              full_address: form.full_address,
              postal_code: form.postal_code,
              mobile_phone_number: form.mobile_phone_number,
              email: form.email,
              decidim_votings_ballot_style_id: ballot_style_for_code(dataset.voting, form.ballot_style_code)&.id
            }

            Decidim::Votings::Census::Datum.create(
              dataset: dataset,
              attributes: attributes
            )
          end

          def ballot_style_for_code(voting, code)
            Decidim::Votings::Admin::BallotStyleByVotingCode.for(voting, code)
          end
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
decidim-elections-0.26.10 app/commands/decidim/votings/census/admin/create_datum.rb
decidim-elections-0.26.9 app/commands/decidim/votings/census/admin/create_datum.rb
decidim-elections-0.26.8 app/commands/decidim/votings/census/admin/create_datum.rb
decidim-elections-0.26.7 app/commands/decidim/votings/census/admin/create_datum.rb
decidim-elections-0.26.5 app/commands/decidim/votings/census/admin/create_datum.rb
decidim-elections-0.26.4 app/commands/decidim/votings/census/admin/create_datum.rb
decidim-elections-0.26.3 app/commands/decidim/votings/census/admin/create_datum.rb
decidim-elections-0.26.2 app/commands/decidim/votings/census/admin/create_datum.rb
decidim-elections-0.26.1 app/commands/decidim/votings/census/admin/create_datum.rb
decidim-elections-0.26.0 app/commands/decidim/votings/census/admin/create_datum.rb
decidim-elections-0.26.0.rc2 app/commands/decidim/votings/census/admin/create_datum.rb
decidim-elections-0.26.0.rc1 app/commands/decidim/votings/census/admin/create_datum.rb
decidim-elections-0.25.2 app/commands/decidim/votings/census/admin/create_datum.rb
decidim-elections-0.25.1 app/commands/decidim/votings/census/admin/create_datum.rb
decidim-elections-0.25.0 app/commands/decidim/votings/census/admin/create_datum.rb
decidim-elections-0.25.0.rc4 app/commands/decidim/votings/census/admin/create_datum.rb
decidim-elections-0.25.0.rc3 app/commands/decidim/votings/census/admin/create_datum.rb
decidim-elections-0.25.0.rc2 app/commands/decidim/votings/census/admin/create_datum.rb
decidim-elections-0.25.0.rc1 app/commands/decidim/votings/census/admin/create_datum.rb