Class: SpreeCmCommissioner::Trips::UpdateOpenDatedTrip
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Trips::UpdateOpenDatedTrip
- Includes:
- Spree::ServiceModule::Base
- Defined in:
- app/services/spree_cm_commissioner/trips/update_open_dated_trip.rb
Overview
Service class responsible for updating an existing Open Dated trip. Handles updates to trip, product, and variant only. Ignored trip stops and service calendar since Open Dated trips don’t have them.
Instance Method Summary collapse
-
#call(trip:, trip_form:) ⇒ Object
Main service method that orchestrates trip updates within a database transaction.
Instance Method Details
#call(trip:, trip_form:) ⇒ Object
Main service method that orchestrates trip updates within a database transaction. Updates trip/product and variant if price provided. Returns success with updated objects or failure with error message.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/services/spree_cm_commissioner/trips/update_open_dated_trip.rb', line 12 def call(trip:, trip_form:) return failure(nil, 'Trip is not open dated') unless trip.open_dated? ApplicationRecord.transaction do update_trip_and_product(trip, trip_form) update_variant(trip, trip_form) if trip_form.price.present? success(trip: trip, variant: trip.product.variants.first) end rescue StandardError => e CmAppLogger.error( label: 'SpreeCmCommissioner::Trips::UpdateOpenDatedTrip#call', data: { error_class: e.class.name, error_message: e., trip_id: trip&.id } ) failure(nil, e.) end |