Class: SpreeCmCommissioner::Trips::UpdateSingleLeg
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Trips::UpdateSingleLeg
- Includes:
- Spree::ServiceModule::Base
- Defined in:
- app/services/spree_cm_commissioner/trips/update_single_leg.rb
Overview
Service class responsible for updating an existing single-leg trip. Handles updates to trip, product, variant, stops, and calendar in the booking system.
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, variant if price provided, stops, and calendar conditionally. Returns success with updated objects or failure with error message.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/services/spree_cm_commissioner/trips/update_single_leg.rb', line 11 def call(trip:, trip_form:) ApplicationRecord.transaction do update_trip_and_product(trip, trip_form) update_variant(trip, trip_form) if trip_form.price.present? update_trip_stops(trip, trip_form) calendar = update_calendar(trip.product, trip_form.service_calendar) if trip_form.service_calendar.present? success(trip: trip, variant: trip.product.variants.first, calendar: calendar) rescue StandardError => e CmAppLogger.error( label: 'SpreeCmCommissioner::Trips::UpdateSingleLeg#call', data: { error_class: e.class.name, error_message: e. } ) failure(nil, 'Failed to update trip') end end |