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
41
42
43
44
45
|
# File 'app/services/spree_cm_commissioner/intercity_taxi_order/update.rb', line 8
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?
verified_data = verify_and_extract_distance(distance_attributes)
return failure(nil, verified_data[:error]) unless verified_data[:success]
line_item.distance = SpreeCmCommissioner::Distance.new(verified_data[:value])
end
line_item.update!(remark: )
recalculate_service.call(order: order, line_item: line_item)
success(order.reload)
rescue StandardError => e
failure(nil, e.message)
end
|