Sha256: a3344638620b26a6094307911f87b0d950a6220f44f30b54f715195ece08922c

Contents?: true

Size: 791 Bytes

Versions: 80

Compression:

Stored size: 791 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    # A command with all the business to cancel an order.
    class CancelOrder < Rectify::Command
      # Public: Initializes the command.
      #
      # order - The current order for the user.
      def initialize(order)
        @order = order
      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 invalid_order?
        cancel_order!
        broadcast(:ok, @order)
      end

      private

      def invalid_order?
        !@order&.checked_out?
      end

      def cancel_order!
        @order.destroy!
      end
    end
  end
end

Version data entries

80 entries across 80 versions & 2 rubygems

Version Path
decidim-budgets-0.18.1 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.17.2 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.18.0 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.17.1 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.16.1 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.17.0 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.16.0 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.15.2 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.15.1 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.15.0 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.14.4 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.14.3 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.14.2 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.14.1 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.13.1 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.12.2 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.13.0 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.12.1 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.13.0.pre1 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.12.0 app/commands/decidim/budgets/cancel_order.rb