Sha256: cf5f16c49d684482c7480a0024cfd42ec7c2393a672a2444c4c6861c92e2870a

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Decidim
  module ActionDelegator
    module Admin
      class UpdateParticipant < Decidim::Command
        # Public: Initializes the command.
        #
        # form         - A form object with the params.
        def initialize(form, participant)
          @form = form
          @participant = participant
        end

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

          update_participant

          broadcast(:ok, participant)
        end

        private

        attr_reader :form, :participant

        def update_participant
          participant.email = form.email
          participant.phone = form.phone
          participant.decidim_action_delegator_ponderation_id = form.decidim_action_delegator_ponderation_id
          participant.save!
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
decidim-action_delegator-0.8.1 app/commands/decidim/action_delegator/admin/update_participant.rb