Sha256: cb6f6cb9e19403049b64ac67f0568ee2ab48c9ae6d3128cbee864e176d3981de

Contents?: true

Size: 797 Bytes

Versions: 7

Compression:

Stored size: 797 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # This command updates the user's interests.
  class UpdateUserInterests < Decidim::Command
    delegate :current_user, to: :form

    # Updates a user's interests.
    #
    # form - The form with the data.
    def initialize(form)
      @form = form
    end

    def call
      return broadcast(:invalid) unless @form.valid?

      update_interests
      current_user.save!

      broadcast(:ok)
    end

    private

    attr_reader :form

    def update_interests
      current_user.extended_data ||= {}
      current_user.extended_data["interested_scopes"] = selected_scopes_ids
    end

    def selected_scopes_ids
      @form.scopes.map do |scope|
        next unless scope.checked?

        scope.id.to_i
      end.compact
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-core-0.29.2 app/commands/decidim/update_user_interests.rb
decidim-core-0.29.1 app/commands/decidim/update_user_interests.rb
decidim-core-0.29.0 app/commands/decidim/update_user_interests.rb
decidim-core-0.29.0.rc4 app/commands/decidim/update_user_interests.rb
decidim-core-0.29.0.rc3 app/commands/decidim/update_user_interests.rb
decidim-core-0.29.0.rc2 app/commands/decidim/update_user_interests.rb
decidim-core-0.29.0.rc1 app/commands/decidim/update_user_interests.rb