Class: SpreeCmCommissioner::Trips::ServiceCalendars::CreateOrUpdate
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Trips::ServiceCalendars::CreateOrUpdate
- Includes:
- Spree::ServiceModule::Base
- Defined in:
- app/services/spree_cm_commissioner/trips/service_calendars/create_or_update.rb
Overview
Service to create or update a service calendar for a calendarable entity.
Instance Method Summary collapse
-
#call(calendarable:, name:, start_date:, end_date:, weekdays:, exception_rules: []) ⇒ Object
rubocop:disable Metrics/ParameterLists.
Instance Method Details
#call(calendarable:, name:, start_date:, end_date:, weekdays:, exception_rules: []) ⇒ Object
rubocop:disable Metrics/ParameterLists
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/services/spree_cm_commissioner/trips/service_calendars/create_or_update.rb', line 8 def call(calendarable:, name:, start_date:, end_date:, weekdays:, exception_rules: []) # rubocop:disable Metrics/ParameterLists return failure(nil, 'calendarable must be present') if calendarable.blank? return failure(nil, 'name must be present') if name.blank? return failure(nil, 'start_date must be present') if start_date.blank? return failure(nil, 'end_date must be present') if end_date.blank? return failure(nil, 'weekdays must be present') if weekdays.blank? ApplicationRecord.transaction do calendar = create_or_update_calendar(calendarable, name, start_date, end_date, weekdays, exception_rules) success(calendar: calendar) end rescue StandardError => e CmAppLogger.error( label: 'SpreeCmCommissioner::Trips::ServiceCalendars::CreateOrUpdate#call', data: { error_class: e.class.name, error_message: e. } ) failure(nil, 'Failed to create service calendar') end |