Sha256: 8badf7158de15f993b9c6e720d000acd685cfc7f70a372c274338b3e3a871fca
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 KB
Contents
# frozen_string_literal: true module Decidim module Lausanne module Budgets # A command with all the business to cancel an order. class CancelOrder < Decidim::Lausanne::Budgets::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. # # Returns nothing. def call transaction do cancel_order! end broadcast(:ok, @order) end private def user_record @order.user_record end # If the order is not linked to a user, # remove the user_record and the order. # If the order is linked to a user, remove all the votes def cancel_order! @order.line_items.each do |line| line.destroy! end unless user_record.user @order.user_record.destroy! end @order.update(checked_out_at: nil) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
decidim-lausanne-budgets-0.1.0 | app/commands/decidim/lausanne/budgets/cancel_order.rb |