Class: Decidim::EnhancedTextwork::UnvoteParagraph

Inherits:
Rectify::Command
  • Object
show all
Defined in:
app/commands/decidim/enhanced_textwork/unvote_paragraph.rb

Overview

A command with all the business logic when a user unvotes a paragraph.

Instance Method Summary collapse

Constructor Details

#initialize(paragraph, current_user) ⇒ UnvoteParagraph

Public: Initializes the command.

paragraph - A Decidim::EnhancedTextwork::Paragraph object. current_user - The current user.



11
12
13
14
# File 'app/commands/decidim/enhanced_textwork/unvote_paragraph.rb', line 11

def initialize(paragraph, current_user)
  @paragraph = paragraph
  @current_user = current_user
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid, together with the paragraph.

  • :invalid if the form wasn't valid and we couldn't proceed.

Returns nothing.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/commands/decidim/enhanced_textwork/unvote_paragraph.rb', line 22

def call
  ActiveRecord::Base.transaction do
    ParagraphVote.where(
      author: @current_user,
      paragraph: @paragraph
    ).destroy_all

    update_temporary_votes
  end

  Decidim::Gamification.decrement_score(@current_user, :paragraph_votes)

  broadcast(:ok, @paragraph)
end