Sha256: aa7d9673ec3bbd84734804a962706e9f178ce8a22a47b6cd809d40f2ab25f1a5

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Decidim
  module ParticipatoryDocuments
    module Admin
      class CreateSuggestionNote < Decidim::Command
        # Public: Initializes the command.
        #
        # form         - A form object with the params.
        # suggestion - the suggestion to relate.
        def initialize(form, suggestion)
          @form = form
          @suggestion = suggestion
        end

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

          create_suggestion_note
          # notify_admins_and_valuators

          broadcast(:ok, suggestion_note)
        end

        private

        attr_reader :form, :suggestion_note, :suggestion

        def create_suggestion_note
          @suggestion_note = Decidim.traceability.create!(
            SuggestionNote,
            form.current_user,
            {
              body: form.body,
              suggestion: suggestion,
              author: form.current_user
            }
          )
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-participatory_documents-0.2.2 app/commands/decidim/participatory_documents/admin/create_suggestion_note.rb
decidim-participatory_documents-0.2.1 app/commands/decidim/participatory_documents/admin/create_suggestion_note.rb
decidim-participatory_documents-0.2.0 app/commands/decidim/participatory_documents/admin/create_suggestion_note.rb