Class: SpreeCmCommissioner::IntercityTaxiOrder::Update

Inherits:
Object
  • Object
show all
Includes:
Spree::ServiceModule::Base
Defined in:
app/services/spree_cm_commissioner/intercity_taxi_order/update.rb

Instance Method Summary collapse

Instance Method Details

#call(order:, remark: nil, pickup_map_place_attributes: nil, dropoff_map_place_attributes: nil, distance_attributes: nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/services/spree_cm_commissioner/intercity_taxi_order/update.rb', line 6

def call(
  order:,
  remark: nil,
  pickup_map_place_attributes: nil,
  dropoff_map_place_attributes: nil,
  distance_attributes: nil
)
  line_item = order.line_items.first

  raise ArgumentError, 'Order has no line items' if line_item.blank?

  if pickup_map_place_attributes.present?
    line_item.pickup_map_place = SpreeCmCommissioner::IntercityTaxi::MapPlace.new(
      pickup_map_place_attributes
    )
  end

  if dropoff_map_place_attributes.present?
    line_item.dropoff_map_place = SpreeCmCommissioner::IntercityTaxi::MapPlace.new(
      dropoff_map_place_attributes
    )
  end

  if distance_attributes.present?
    line_item.distance = SpreeCmCommissioner::IntercityTaxi::Distance.new(
      distance_attributes
    )
  end

  line_item.update!(remark: remark)

  success(order.reload)
rescue StandardError => e
  failure(nil, e.message)
end