Class: Decidim::Verifications::CsvCensus::Admin::CreateCensusData

Inherits:
Command
  • Object
show all
Defined in:
app/commands/decidim/verifications/csv_census/admin/create_census_data.rb

Overview

A command with the business logic to create census data for a organization.

Instance Method Summary collapse

Constructor Details

#initialize(form, organization) ⇒ CreateCensusData

Returns a new instance of CreateCensusData.



10
11
12
13
# File 'app/commands/decidim/verifications/csv_census/admin/create_census_data.rb', line 10

def initialize(form, organization)
  @form = form
  @organization = organization
end

Instance Method Details

#callObject

Executes the command. Broadcast this events:

  • :ok when everything is valid

  • :invalid when the form was not valid and could not proceed-

Returns nothing.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/commands/decidim/verifications/csv_census/admin/create_census_data.rb', line 20

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