Sha256: 9dbd1cde6729486b5cb3e70ab42045f8eccb74e398140ad57bacb30076a5ded9

Contents?: true

Size: 792 Bytes

Versions: 30

Compression:

Stored size: 792 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    # A command with all the business to cancel an order.
    class CancelOrder < Decidim::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

30 entries across 30 versions & 1 rubygems

Version Path
decidim-budgets-0.30.0.rc3 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.30.0.rc2 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.30.0.rc1 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.29.2 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.28.5 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.29.1 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.28.4 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.27.9 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.29.0 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.28.3 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.27.8 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.29.0.rc4 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.29.0.rc3 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.29.0.rc2 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.29.0.rc1 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.28.2 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.27.7 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.28.1 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.27.6 app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.28.0 app/commands/decidim/budgets/cancel_order.rb