Class: SpreeCmCommissioner::VendorRouteMetrics::DecreaseTripCount

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

Instance Method Summary collapse

Instance Method Details

#call(vendor_route_metric:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'app/services/spree_cm_commissioner/vendor_route_metrics/decrease_trip_count.rb', line 6

def call(vendor_route_metric:)
  return failure(nil, 'Vendor route metric not found') unless vendor_route_metric

  vendor_route_metric.with_lock do
    vendor_route_metric.update!(trip_count: [vendor_route_metric.trip_count - 1, 0].max)
  end

  success(vendor_route_metric: vendor_route_metric)
rescue StandardError => e
  failure(nil, e.message)
end