Sha256: 4e91efb1acca099e322818c19cab2a1e8120b68ea8c8efdb469cfe0c2577698c
Contents?: true
Size: 1.7 KB
Versions: 6
Compression:
Stored size: 1.7 KB
Contents
# frozen_string_literal: true module Decidim module Votings module Admin # A command with all the business logic when creating a new voting space class CreateVoting < Rectify::Command # Public: Initializes the command. # # form - A form object with the params. def initialize(form) @form = form 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? voting = create_voting! if voting.persisted? broadcast(:ok, voting) else form.errors.add(:banner_image, voting.errors[:banner_image]) if voting.errors.include? :banner_image form.errors.add(:introductory_image, voting.errors[:introductory_image]) if voting.errors.include? :introductory_image broadcast(:invalid) end end private attr_reader :form def create_voting! Decidim.traceability.create( Voting, form.current_user, organization: form.current_organization, title: form.title, slug: form.slug, description: form.description, scope: form.scope, start_time: form.start_time, end_time: form.end_time, promoted: form.promoted, banner_image: form.banner_image, introductory_image: form.introductory_image, voting_type: form.voting_type ) end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems