Sha256: cd56b8cc548db4b0eb5dfd8b8662624669f350b814da5703c267729598fd11cb
Contents?: true
Size: 875 Bytes
Versions: 6
Compression:
Stored size: 875 Bytes
Contents
# frozen_string_literal: true module Decidim module Elections module Admin # This command is executed when an admin marks an answer # as selected. class UpdateAnswerSelection < Rectify::Command def initialize(answer, selected) @answer = answer @selected = selected end # Selects the answer if valid. # # Broadcasts :ok if successful, :invalid otherwise. def call return broadcast(:invalid) if invalid? update_answer_selection! broadcast(:ok, answer) end private attr_reader :answer, :selected def invalid? !answer.question.total_votes.positive? end def update_answer_selection! answer.update!( selected: selected ) end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems