Sha256: 5fdca7befb2c6a2d862b36f571898d7124bad9e8696720f52a07d24d9abcef37

Contents?: true

Size: 790 Bytes

Versions: 13

Compression:

Stored size: 790 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

13 entries across 13 versions & 2 rubygems

Version Path
decidim-budgets-0.1.0 app/commands/decidim/budgets/cancel_order.rb
decidim-0.1.0 decidim-budgets/app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.0.8.1 app/commands/decidim/budgets/cancel_order.rb
decidim-0.0.8.1 decidim-budgets/app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.0.7 app/commands/decidim/budgets/cancel_order.rb
decidim-0.0.7 decidim-budgets/app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.0.6 app/commands/decidim/budgets/cancel_order.rb
decidim-0.0.6 decidim-budgets/app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.0.5 app/commands/decidim/budgets/cancel_order.rb
decidim-0.0.5 decidim-budgets/app/commands/decidim/budgets/cancel_order.rb
decidim-0.0.4 decidim-budgets/app/commands/decidim/budgets/cancel_order.rb
decidim-budgets-0.0.3 app/commands/decidim/budgets/cancel_order.rb
decidim-0.0.3 decidim-budgets/app/commands/decidim/budgets/cancel_order.rb