Sha256: 012610de55279d9f56d01f82737165e4268bab7af7cdbd4d93b5fbc3649f1500

Contents?: true

Size: 889 Bytes

Versions: 80

Compression:

Stored size: 889 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    # A command with all the business to add remove line items from orders
    class RemoveLineItem < Rectify::Command
      # Public: Initializes the command.
      #
      # order - The current order for the user
      # project - The the project to remove from the order
      def initialize(order, project)
        @order = order
        @project = project
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when everything is valid.
      # - :invalid if the there is an error.
      #
      # Returns nothing.
      def call
        return broadcast(:invalid) if @order.checked_out?
        remove_line_item
        broadcast(:ok, @order)
      end

      private

      def remove_line_item
        @order.projects.destroy(@project)
        @order.save!
      end
    end
  end
end

Version data entries

80 entries across 80 versions & 2 rubygems

Version Path
decidim-budgets-0.5.0 app/commands/decidim/budgets/remove_line_item.rb
decidim-0.5.0 decidim-budgets/app/commands/decidim/budgets/remove_line_item.rb
decidim-budgets-0.4.4 app/commands/decidim/budgets/remove_line_item.rb
decidim-0.4.4 decidim-budgets/app/commands/decidim/budgets/remove_line_item.rb
decidim-budgets-0.4.3 app/commands/decidim/budgets/remove_line_item.rb
decidim-budgets-0.4.2 app/commands/decidim/budgets/remove_line_item.rb
decidim-budgets-0.4.1 app/commands/decidim/budgets/remove_line_item.rb
decidim-0.4.3 decidim-budgets/app/commands/decidim/budgets/remove_line_item.rb
decidim-0.4.2 decidim-budgets/app/commands/decidim/budgets/remove_line_item.rb
decidim-0.4.1 decidim-budgets/app/commands/decidim/budgets/remove_line_item.rb
decidim-budgets-0.4.0 app/commands/decidim/budgets/remove_line_item.rb
decidim-0.4.0 decidim-budgets/app/commands/decidim/budgets/remove_line_item.rb
decidim-budgets-0.3.2 app/commands/decidim/budgets/remove_line_item.rb
decidim-0.3.2 decidim-budgets/app/commands/decidim/budgets/remove_line_item.rb
decidim-budgets-0.3.1 app/commands/decidim/budgets/remove_line_item.rb
decidim-0.3.1 decidim-budgets/app/commands/decidim/budgets/remove_line_item.rb
decidim-budgets-0.3.0 app/commands/decidim/budgets/remove_line_item.rb
decidim-0.3.0 decidim-budgets/app/commands/decidim/budgets/remove_line_item.rb
decidim-budgets-0.2.0 app/commands/decidim/budgets/remove_line_item.rb
decidim-0.2.0 decidim-budgets/app/commands/decidim/budgets/remove_line_item.rb