Sha256: dee93ae753ec7623c924474b12791d01cffe334651a78c1ecd0bb84a33c00590

Contents?: true

Size: 1.05 KB

Versions: 9

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 wasn't valid and couldn't 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

9 entries across 9 versions & 1 rubygems

Version Path
decidim-verifications-0.27.9 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb
decidim-verifications-0.27.8 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb
decidim-verifications-0.27.7 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb
decidim-verifications-0.27.6 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb
decidim-verifications-0.27.5 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb
decidim-verifications-0.27.4 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb
decidim-verifications-0.27.3 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb
decidim-verifications-0.27.2 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb
decidim-verifications-0.27.1 app/commands/decidim/verifications/csv_census/admin/create_census_data.rb