Sha256: 6819c0a6e2707527189f90d21ebfd58894689477745fdd2994d2a8ce996014f9
Contents?: true
Size: 1002 Bytes
Versions: 13
Compression:
Stored size: 1002 Bytes
Contents
# frozen_string_literal: true module Decidim module Initiatives # A command with all the business logic when a user or organization unvotes an initiative. class UnvoteInitiative < Decidim::Command # Public: Initializes the command. # # initiative - A Decidim::Initiative object. # current_user - The current user. def initialize(initiative, current_user) @initiative = initiative @current_user = current_user end # Executes the command. Broadcasts these events: # # - :ok when everything is valid, together with the initiative. # - :invalid if the form was not valid and we could not proceed. # # Returns nothing. def call destroy_initiative_vote broadcast(:ok, @initiative) end private def destroy_initiative_vote Initiative.transaction do @initiative.votes.where(author: @current_user).destroy_all end end end end end
Version data entries
13 entries across 13 versions & 1 rubygems