Sha256: e341162259133b2ae90f9fb40ca5a3e86eeb9299562bb212fdf9fdd8ff612588

Contents?: true

Size: 1.05 KB

Versions: 13

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Decidim
  module Verifications
    module CsvCensus
      module Admin
        # A command with the business logic to create census data for a
        # organization.
        class CreateCensusData < Decidim::Command
          def initialize(form, organization)
            @form = form
            @organization = organization
          end

          # Executes the command. Broadcast this events:
          # - :ok when everything is valid
          # - :invalid when the form was not valid and could not proceed-
          #
          # Returns nothing.
          def call
            return broadcast(:invalid) unless @form.file

            data = @form.data
            return broadcast(:invalid) unless data

            # rubocop:disable Rails/SkipsModelValidations
            CsvDatum.insert_all(@organization, data.values)
            # rubocop:enable Rails/SkipsModelValidations
            RemoveDuplicatesJob.perform_later(@organization)

            broadcast(:ok)
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-verifications-0.29.1 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb
decidim-verifications-0.28.4 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb
decidim-verifications-0.29.0 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb
decidim-verifications-0.28.3 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb
decidim-verifications-0.29.0.rc4 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb
decidim-verifications-0.29.0.rc3 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb
decidim-verifications-0.29.0.rc2 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb
decidim-verifications-0.29.0.rc1 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb
decidim-verifications-0.28.2 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb
decidim-verifications-0.28.1 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb
decidim-verifications-0.28.0 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb
decidim-verifications-0.28.0.rc5 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb
decidim-verifications-0.28.0.rc4 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb