Class: SpreeCmCommissioner::Routes::Update

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

Instance Method Summary collapse

Instance Method Details

#call(vendor:, route:, route_params:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/services/spree_cm_commissioner/routes/update.rb', line 6

def call(vendor:, route:, route_params:)
  # vendor_id, tenant_id, origin_place_id, destination_place_id are excluded and set automatically.
  # route_stops is not updateable.
  attrs = ::Spree::PermittedAttributes.route_attributes
                                      .index_with { |attr_key| route_params[attr_key] }
                                      .except(:vendor_id, :tenant_id, :route_stops, :origin_place_id, :destination_place_id)
                                      .compact

  route = vendor.routes.find_by(id: route.id)
  return failure(nil, :route_not_found) if route.nil?

  if route.update(attrs)
    success(route: route)
  else
    failure(route.errors)
  end
end