Class: SpreeCmCommissioner::Trips::CreateMultiLeg
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Trips::CreateMultiLeg
- Includes:
- Spree::ServiceModule::Base, SpreeCmCommissioner::Transit::TripHelper
- Defined in:
- app/services/spree_cm_commissioner/trips/create_multi_leg.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- DEFAULT_MIN_TRANSFER_WINDOW_MINUTES =
ENV.fetch('MIN_TRANSFER_WINDOW_MINUTES', '0').to_i
- DEFAULT_MAX_TRANSFER_WINDOW_MINUTES =
ENV.fetch('MAX_TRANSFER_WINDOW_MINUTES', '240').to_i
Instance Method Summary collapse
Methods included from SpreeCmCommissioner::Transit::TripHelper
#minutes_since_midnight, #normalize_date, #parse_date, #parse_time
Instance Method Details
#call(vendor:, trip_form:, min_transfer_window_minutes: nil, max_transfer_window_minutes: nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/services/spree_cm_commissioner/trips/create_multi_leg.rb', line 28 def call(vendor:, trip_form:, min_transfer_window_minutes: nil, max_transfer_window_minutes: nil) return failure(nil, trip_form.errors..to_sentence) unless trip_form.valid_data? setup_context( vendor: vendor, trip_form: trip_form, min_transfer_window_minutes: min_transfer_window_minutes, max_transfer_window_minutes: max_transfer_window_minutes ) validate_stop_rows! @segments = calculate_segments_by_branches return failure(nil, 'Trip stops must have at least 2 branch stops') if @segments.blank? ApplicationRecord.transaction do parent_route = ensure_parent_route! leg_trips, segment_to_trip_map = resolve_legs_and_apply_segment_stops! validate_transfer_windows!(leg_trips) first_branch = first_branch_stop! parent_variant = create_variant!(first_stop: first_branch) parent_trip = create_parent_trip!( route: parent_route, trip_form: @trip_form, variant: parent_variant ) setup_parent_branch_stops!( parent_trip: parent_trip, segment_to_trip_map: segment_to_trip_map ) calendar = setup_calendar!(parent_variant.product, @trip_form.service_calendar) success( trip: parent_trip, legs: leg_trips, variant: parent_variant, calendar: calendar ) end rescue StandardError => e CmAppLogger.error( label: 'SpreeCmCommissioner::Trips::CreateMultiLeg#call', data: { error_class: e.class.name, error_message: e. } ) failure(nil, e.) end |