Sha256: ae29ed57f5d79a17fb92e2c3e6401373f19971d37c109ea950a31b94f3d9a612
Contents?: true
Size: 1.14 KB
Versions: 31
Compression:
Stored size: 1.14 KB
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 < Rectify::Command # Public: Initializes the command. # # initiative - A Decidim::Initiative object. # current_user - The current user. # group_id - Decidim user group id def initialize(initiative, current_user, group_id) @initiative = initiative @current_user = current_user @decidim_user_group_id = group_id end # Executes the command. Broadcasts these events: # # - :ok when everything is valid, together with the initiative. # - :invalid if the form wasn't valid and we couldn't proceed. # # Returns nothing. def call destroy_initiative_vote broadcast(:ok, @initiative) end private def destroy_initiative_vote @initiative .votes .where( author: @current_user, decidim_user_group_id: @decidim_user_group_id ) .destroy_all end end end end
Version data entries
31 entries across 31 versions & 1 rubygems