Sha256: 19fed561b98bf2c947ae56ea949789ba1595e497e4dbf4fc70c3469ffb3809d1
Contents?: true
Size: 1.28 KB
Versions: 18
Compression:
Stored size: 1.28 KB
Contents
# frozen_string_literal: true module Decidim module Proposals # A command with all the business logic when a user creates a new proposal. class CreateProposal < Rectify::Command # Public: Initializes the command. # # form - A form object with the params. # current_user - The current user. def initialize(form, current_user) @form = form @current_user = current_user end # Executes the command. Broadcasts these events: # # - :ok when everything is valid, together with the proposal. # - :invalid if the form wasn't valid and we couldn't proceed. # # Returns nothing. def call return broadcast(:invalid) if form.invalid? create_proposal broadcast(:ok, proposal) end private attr_reader :form, :proposal def create_proposal @proposal = Proposal.create!( title: form.title, body: form.body, category: form.category, scope: form.scope, author: @current_user, decidim_user_group_id: form.user_group_id, feature: form.feature, address: form.address, latitude: form.latitude, longitude: form.longitude ) end end end end
Version data entries
18 entries across 18 versions & 2 rubygems