spree_cm_commissioner 2.5.6 → 2.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/app/controllers/spree_cm_commissioner/application_controller_decorator.rb +0 -1
- data/app/controllers/spree_cm_commissioner/orders_controller.rb +20 -7
- data/app/jobs/spree_cm_commissioner/integrations/cleanup_sync_sessions_job.rb +11 -0
- data/app/models/spree_cm_commissioner/order_decorator.rb +4 -0
- data/app/overrides/spree/admin/orders/_order_actions/actions.html.erb.deface +1 -1
- data/app/services/spree_cm_commissioner/integrations/cleanup_sync_sessions.rb +47 -0
- data/app/services/spree_cm_commissioner/orders/jwt_token/generate.rb +30 -0
- data/app/services/spree_cm_commissioner/orders/jwt_token/verify.rb +44 -0
- data/app/services/spree_cm_commissioner/trips/create_single_leg.rb +28 -17
- data/app/services/spree_cm_commissioner/trips/update_single_leg.rb +5 -1
- data/app/services/spree_cm_commissioner/trips/variants/create.rb +4 -7
- data/lib/spree_cm_commissioner/transit/route_stop.rb +3 -3
- data/lib/spree_cm_commissioner/transit/service_calendar_form.rb +54 -0
- data/lib/spree_cm_commissioner/transit/trip_form.rb +25 -0
- data/lib/spree_cm_commissioner/transit/trip_stop_form.rb +30 -2
- data/lib/spree_cm_commissioner/version.rb +1 -1
- data/lib/spree_cm_commissioner.rb +1 -0
- metadata +7 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 97f3fed7571f41eef6ea0f3f695adc586ae260b0d6c1b85946446d597eaf5b7d
|
|
4
|
+
data.tar.gz: bf5e6399b60e7471a50aaef9a42651d16f7339bfb55389a1d1d8f6672222b496
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7c7f4892c0eb3380b460274fd7a3c5eb2acf08f1b2ae433a38a81691aa12bbb1286ce1123060c249a954d5afe397b5f8d308eb804baaa8c240f663fbbeb77d29
|
|
7
|
+
data.tar.gz: 5cd89d5fbe279b5d26174e20074a2c1726459faf9ce11939584629a8f33888c3a884872e0b819b95809aa97bdbfc14338e1e4a4482cab911ac203550e4eb48d3
|
data/Gemfile.lock
CHANGED
|
@@ -2,7 +2,6 @@ module SpreeCmCommissioner
|
|
|
2
2
|
module ApplicationControllerDecorator
|
|
3
3
|
def self.prepended(base)
|
|
4
4
|
base.include SpreeCmCommissioner::ExceptionNotificable
|
|
5
|
-
base.include SpreeCmCommissioner::ContentCachable
|
|
6
5
|
end
|
|
7
6
|
|
|
8
7
|
# Annonymous block: https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Naming/BlockForwarding
|
|
@@ -1,11 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
module SpreeCmCommissioner
|
|
2
|
+
class OrdersController < ApplicationController
|
|
3
|
+
layout 'spree_cm_commissioner/layouts/order_mailer'
|
|
4
|
+
helper 'spree/mail'
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
def show
|
|
7
|
+
@order = if params[:id].match?(/^R\d{9,}-([A-Za-z0-9_\-]+)$/)
|
|
8
|
+
Spree::Order.search_by_qr_data!(params[:id])
|
|
9
|
+
else
|
|
10
|
+
SpreeCmCommissioner::Orders::Tickets::VerifyToken.call(token: params[:id]).value[:order]
|
|
11
|
+
end
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
@product_type = @order.products.first&.product_type || 'accommodation'
|
|
14
|
+
|
|
15
|
+
if @order.tenant.present?
|
|
16
|
+
@name = @order.tenant.name
|
|
17
|
+
@logo = @order.tenant.active_vendor&.logo&.original_url
|
|
18
|
+
@brand_color = @order.tenant.preferred_brand_primary_color
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
render :template => 'spree/order_mailer/confirm_email'
|
|
22
|
+
end
|
|
10
23
|
end
|
|
11
24
|
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module SpreeCmCommissioner
|
|
2
|
+
module Integrations
|
|
3
|
+
class CleanupSyncSessionsJob < SpreeCmCommissioner::ApplicationJob
|
|
4
|
+
queue_as :default
|
|
5
|
+
|
|
6
|
+
def perform(cutoff_days = SpreeCmCommissioner::Integrations::CleanupSyncSessions::DEFAULT_CUTOFF_DAYS)
|
|
7
|
+
SpreeCmCommissioner::Integrations::CleanupSyncSessions.new.call(cutoff_days: cutoff_days)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -251,6 +251,10 @@ module SpreeCmCommissioner
|
|
|
251
251
|
"#{number}-#{token}"
|
|
252
252
|
end
|
|
253
253
|
|
|
254
|
+
def jwt_qr_data
|
|
255
|
+
SpreeCmCommissioner::Orders::JwtToken::Generate.call(order: self).value[:token]
|
|
256
|
+
end
|
|
257
|
+
|
|
254
258
|
def display_outstanding_balance
|
|
255
259
|
Spree::Money.new(outstanding_balance, currency: currency).to_s
|
|
256
260
|
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module SpreeCmCommissioner
|
|
2
|
+
module Integrations
|
|
3
|
+
class CleanupSyncSessions
|
|
4
|
+
prepend ::Spree::ServiceModule::Base
|
|
5
|
+
|
|
6
|
+
DEFAULT_CUTOFF_DAYS = 30
|
|
7
|
+
BATCH_SIZE = 500
|
|
8
|
+
|
|
9
|
+
# Deletes IntegrationSyncSession records older than the cutoff (default: 30 days).
|
|
10
|
+
# Runs in batches to avoid long-running single queries.
|
|
11
|
+
def call(cutoff_days: DEFAULT_CUTOFF_DAYS, batch_size: BATCH_SIZE)
|
|
12
|
+
cutoff_time = cutoff_days.days.ago
|
|
13
|
+
deleted_count = 0
|
|
14
|
+
|
|
15
|
+
SpreeCmCommissioner::IntegrationSyncSession
|
|
16
|
+
.where('created_at < ?', cutoff_time)
|
|
17
|
+
.in_batches(of: batch_size) do |relation|
|
|
18
|
+
deleted_count += relation.delete_all
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
CmAppLogger.log(
|
|
22
|
+
label: 'SpreeCmCommissioner::Integrations::CleanupSyncSessions#call completed',
|
|
23
|
+
data: {
|
|
24
|
+
cutoff_days: cutoff_days,
|
|
25
|
+
batch_size: batch_size,
|
|
26
|
+
deleted_count: deleted_count
|
|
27
|
+
}
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
success(deleted_count: deleted_count, cutoff_days: cutoff_days)
|
|
31
|
+
rescue StandardError => e
|
|
32
|
+
CmAppLogger.error(
|
|
33
|
+
label: 'SpreeCmCommissioner::Integrations::CleanupSyncSessions#call failed',
|
|
34
|
+
data: {
|
|
35
|
+
cutoff_days: cutoff_days,
|
|
36
|
+
batch_size: batch_size,
|
|
37
|
+
error_class: e.class.name,
|
|
38
|
+
error_message: e.message,
|
|
39
|
+
backtrace: e.backtrace&.first(5)&.join("\n")
|
|
40
|
+
}
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
failure(nil, e.message)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module SpreeCmCommissioner
|
|
2
|
+
module Orders::JwtToken
|
|
3
|
+
class Generate
|
|
4
|
+
prepend ::Spree::ServiceModule::Base
|
|
5
|
+
|
|
6
|
+
def call(order:)
|
|
7
|
+
nonce = generate_nonce
|
|
8
|
+
token = "#{order.number}?jwt_token=#{nonce}-#{generate_qr_jwt(order: order, nonce: nonce)}"
|
|
9
|
+
|
|
10
|
+
success(token: token)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def generate_nonce
|
|
16
|
+
SecureRandom.alphanumeric(6).upcase
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def generate_qr_jwt(order:, nonce:)
|
|
20
|
+
payload = {
|
|
21
|
+
order_number: order.number,
|
|
22
|
+
nonce: nonce,
|
|
23
|
+
exp: 1.day.from_now.to_i
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
JWT.encode(payload, order.token, 'HS256')
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module SpreeCmCommissioner
|
|
2
|
+
module Orders::JwtToken
|
|
3
|
+
class Verify
|
|
4
|
+
prepend ::Spree::ServiceModule::Base
|
|
5
|
+
|
|
6
|
+
def call(token:)
|
|
7
|
+
# split token into nonce and jwt_token
|
|
8
|
+
nonce, jwt_token = token.split('-', 2)
|
|
9
|
+
|
|
10
|
+
# Decode WITHOUT verification
|
|
11
|
+
unverified_payload, = JWT.decode(jwt_token, nil, false)
|
|
12
|
+
|
|
13
|
+
# Validate nonce FIRST (no DB hit)
|
|
14
|
+
validate_nonce!(unverified_payload['nonce'], nonce)
|
|
15
|
+
|
|
16
|
+
# Find order
|
|
17
|
+
order = Spree::Order.find_by!(number: unverified_payload['order_number'])
|
|
18
|
+
|
|
19
|
+
# Verify JWT using per-order secret
|
|
20
|
+
payload, = JWT.decode(
|
|
21
|
+
jwt_token,
|
|
22
|
+
order.token,
|
|
23
|
+
true,
|
|
24
|
+
algorithm: 'HS256'
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
success(payload: payload, order: order)
|
|
28
|
+
rescue JWT::ExpiredSignature, JWT::DecodeError, JWT::VerificationError, ActiveRecord::RecordNotFound => _e
|
|
29
|
+
failure(error: 'Invalid or expired token', status: :forbidden)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def validate_nonce!(token_nonce, nonce)
|
|
35
|
+
return if ActiveSupport::SecurityUtils.secure_compare(
|
|
36
|
+
token_nonce.to_s,
|
|
37
|
+
nonce.to_s
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
raise JWT::DecodeError
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -4,6 +4,7 @@ module SpreeCmCommissioner
|
|
|
4
4
|
# Orchestrates the creation of product variant, trip record, stops, calendar, and inventory.
|
|
5
5
|
class CreateSingleLeg
|
|
6
6
|
prepend Spree::ServiceModule::Base
|
|
7
|
+
include Transit::TripHelper
|
|
7
8
|
|
|
8
9
|
# Main service method that validates the trip form and orchestrates creation.
|
|
9
10
|
# Creates variant, trip, calendar, and inventory within a database transaction.
|
|
@@ -36,7 +37,10 @@ module SpreeCmCommissioner
|
|
|
36
37
|
def create_variant!(vendor, trip_form)
|
|
37
38
|
first_stop = trip_form.trip_stops.first
|
|
38
39
|
vehicle_type = SpreeCmCommissioner::VehicleType.find(first_stop.vehicle_type_id)
|
|
39
|
-
capacity = vehicle_type.number_of_seats
|
|
40
|
+
capacity = vehicle_type.number_of_seats || vehicle_type.seat_layout&.total_seats
|
|
41
|
+
|
|
42
|
+
raise StandardError, 'Vehicle type must be selected' if vehicle_type.blank?
|
|
43
|
+
raise StandardError, 'Vehicle type seat capacity must be greater than 0' if capacity <= 0
|
|
40
44
|
|
|
41
45
|
result = SpreeCmCommissioner::Trips::Variants::Create.call(
|
|
42
46
|
vendor: vendor,
|
|
@@ -45,7 +49,7 @@ module SpreeCmCommissioner
|
|
|
45
49
|
capacity: capacity
|
|
46
50
|
)
|
|
47
51
|
|
|
48
|
-
raise result.error unless result.success?
|
|
52
|
+
raise StandardError, result.error unless result.success?
|
|
49
53
|
|
|
50
54
|
result.value[:variant]
|
|
51
55
|
end
|
|
@@ -57,14 +61,18 @@ module SpreeCmCommissioner
|
|
|
57
61
|
last_stop = trip_form.trip_stops.last
|
|
58
62
|
|
|
59
63
|
locations = vendor.locations.where(id: trip_form.trip_stops.map(&:location_id)).index_by(&:id)
|
|
60
|
-
|
|
64
|
+
|
|
65
|
+
# vendor_places are either stops or branches
|
|
66
|
+
vendor_places = SpreeCmCommissioner::VendorPlace
|
|
67
|
+
.where(id: trip_form.trip_stops.map(&:stop_id), vendor: vendor)
|
|
68
|
+
.index_by(&:id)
|
|
61
69
|
|
|
62
70
|
trip = vendor.trips.create!(
|
|
63
71
|
product: variant.product,
|
|
64
72
|
vehicle_type: SpreeCmCommissioner::VehicleType.find_by(id: first_stop.vehicle_type_id),
|
|
65
73
|
vehicle: SpreeCmCommissioner::Vehicle.find_by(id: first_stop.vehicle_id),
|
|
66
|
-
|
|
67
|
-
|
|
74
|
+
origin_place_id: locations[first_stop.location_id.to_i].place_id,
|
|
75
|
+
destination_place_id: locations[last_stop.location_id.to_i].place_id,
|
|
68
76
|
route: vendor.routes.find(trip_form.route_id),
|
|
69
77
|
departure_time: first_stop.departure_time,
|
|
70
78
|
duration: trip_form.total_duration_seconds,
|
|
@@ -73,28 +81,31 @@ module SpreeCmCommissioner
|
|
|
73
81
|
route_type: trip_form.route_type || vendor.routes.find(trip_form.route_id)&.route_type
|
|
74
82
|
)
|
|
75
83
|
|
|
76
|
-
create_trip_stops(trip, trip_form, locations,
|
|
84
|
+
create_trip_stops(trip, trip_form, locations, vendor_places)
|
|
77
85
|
trip
|
|
78
86
|
end
|
|
79
87
|
|
|
80
88
|
# Creates individual trip stops based on the trip form stops.
|
|
81
|
-
# Each stop includes arrival/departure times and boarding/drop-off permissions
|
|
82
|
-
def create_trip_stops(trip, trip_form, locations,
|
|
83
|
-
|
|
89
|
+
# Each stop includes arrival/departure times and boarding/drop-off permissions
|
|
90
|
+
def create_trip_stops(trip, trip_form, locations, vendor_places)
|
|
91
|
+
stops = Array(trip_form.trip_stops)
|
|
92
|
+
previous_stop = nil
|
|
84
93
|
|
|
85
|
-
|
|
86
|
-
|
|
94
|
+
stops.sort_by { |s| s.sequence.to_i }.each_with_index do |ts, _index|
|
|
95
|
+
if previous_stop
|
|
96
|
+
prev_departure = parse_time(previous_stop.departure_time)
|
|
97
|
+
arrival_time = prev_departure + previous_stop.duration_in_hours.to_f.hours if prev_departure
|
|
98
|
+
end
|
|
87
99
|
|
|
88
100
|
trip.trip_stops.create!(
|
|
89
|
-
stop_place:
|
|
90
|
-
location_place: locations[ts.location_id].place,
|
|
101
|
+
stop_place: vendor_places[ts.stop_id.to_i].place,
|
|
102
|
+
location_place: locations[ts.location_id.to_i].place,
|
|
91
103
|
allow_boarding: ts.allow_boarding?,
|
|
92
|
-
allow_drop_off: ts.allow_drop_off
|
|
104
|
+
allow_drop_off: ts.allow_drop_off?,
|
|
93
105
|
arrival_time: arrival_time,
|
|
94
106
|
departure_time: ts.departure_time
|
|
95
107
|
)
|
|
96
|
-
|
|
97
|
-
previous_departure = ts.departure_time
|
|
108
|
+
previous_stop = ts
|
|
98
109
|
end
|
|
99
110
|
end
|
|
100
111
|
|
|
@@ -109,7 +120,7 @@ module SpreeCmCommissioner
|
|
|
109
120
|
exception_rules: calendar_form.exception_rules || []
|
|
110
121
|
)
|
|
111
122
|
|
|
112
|
-
raise res.error unless res.success?
|
|
123
|
+
raise StandardError, res.error unless res.success?
|
|
113
124
|
|
|
114
125
|
res.value[:calendar]
|
|
115
126
|
end
|
|
@@ -9,6 +9,8 @@ module SpreeCmCommissioner
|
|
|
9
9
|
# Updates trip/product, variant if price provided, stops, and calendar conditionally.
|
|
10
10
|
# Returns success with updated objects or failure with error message.
|
|
11
11
|
def call(trip:, trip_form:)
|
|
12
|
+
raise ArgumentError, 'route_id cannot be nil' if trip_form.route_id.nil?
|
|
13
|
+
|
|
12
14
|
ApplicationRecord.transaction do
|
|
13
15
|
update_trip_and_product(trip, trip_form)
|
|
14
16
|
update_variant(trip, trip_form) if trip_form.price.present?
|
|
@@ -47,6 +49,8 @@ module SpreeCmCommissioner
|
|
|
47
49
|
|
|
48
50
|
# Iterates through stops and applies updates only if attributes are present.
|
|
49
51
|
def update_trip_stops(trip, trip_form)
|
|
52
|
+
return if trip_form.trip_stops.blank?
|
|
53
|
+
|
|
50
54
|
trip.trip_stops.each_with_index do |stop, idx|
|
|
51
55
|
ts_form = trip_form.trip_stops[idx]
|
|
52
56
|
next unless ts_form
|
|
@@ -71,7 +75,7 @@ module SpreeCmCommissioner
|
|
|
71
75
|
exception_rules: calendar_form.exception_rules || []
|
|
72
76
|
)
|
|
73
77
|
|
|
74
|
-
raise
|
|
78
|
+
raise StandardError, 'Failed to update service calendar' unless result.success?
|
|
75
79
|
|
|
76
80
|
result.value[:calendar]
|
|
77
81
|
end
|
|
@@ -14,6 +14,7 @@ module SpreeCmCommissioner
|
|
|
14
14
|
return failure(nil, 'price must be present') if price.blank?
|
|
15
15
|
return failure(nil, 'capacity must be present') if capacity.blank?
|
|
16
16
|
return failure(nil, 'capacity must be greater than 0') if capacity <= 0
|
|
17
|
+
return failure(nil, 'name must be present') if trip_form.name.blank?
|
|
17
18
|
|
|
18
19
|
ApplicationRecord.transaction do
|
|
19
20
|
product = create_product!(vendor, trip_form)
|
|
@@ -40,12 +41,8 @@ module SpreeCmCommissioner
|
|
|
40
41
|
# Creates a transit product with name based on stops, assigns vendor, type, and options.
|
|
41
42
|
# Includes seat-type option type and default store association.
|
|
42
43
|
def create_product!(vendor, trip_form)
|
|
43
|
-
vendor_stops = stops(vendor, trip_form)
|
|
44
|
-
first_stop = vendor_stops[trip_form.trip_stops.first.stop_id].place
|
|
45
|
-
last_stop = vendor_stops[trip_form.trip_stops.last.stop_id].place
|
|
46
|
-
|
|
47
44
|
Spree::Product.create!(
|
|
48
|
-
name: trip_form.name.presence
|
|
45
|
+
name: trip_form.name.presence,
|
|
49
46
|
short_name: trip_form.short_name,
|
|
50
47
|
vendor: vendor,
|
|
51
48
|
product_type: 'transit',
|
|
@@ -59,8 +56,8 @@ module SpreeCmCommissioner
|
|
|
59
56
|
end
|
|
60
57
|
|
|
61
58
|
# Retrieves and indexes stops from the vendor for the trip form's stop IDs.
|
|
62
|
-
def
|
|
63
|
-
vendor.
|
|
59
|
+
def branches(vendor, trip_form)
|
|
60
|
+
vendor.branches.where(id: trip_form.trip_stops.map(&:stop_id)).index_by(&:id)
|
|
64
61
|
end
|
|
65
62
|
|
|
66
63
|
# Sets up or finds the seat-type option type and creates normal option value.
|
|
@@ -5,12 +5,12 @@ module SpreeCmCommissioner::Transit
|
|
|
5
5
|
STOP_TYPES = %i[branch stop].freeze
|
|
6
6
|
|
|
7
7
|
def initialize(options = {})
|
|
8
|
-
@location_id = options[:location_id]
|
|
8
|
+
@location_id = options[:location_id]&.to_i
|
|
9
9
|
@type = options[:type]&.to_sym
|
|
10
|
-
@sequence = options[:sequence]
|
|
10
|
+
@sequence = options[:sequence]&.to_i
|
|
11
11
|
|
|
12
12
|
# vendor place is either stop or branch
|
|
13
|
-
@vendor_place_id = options[:vendor_place_id]
|
|
13
|
+
@vendor_place_id = options[:vendor_place_id]&.to_i
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def self.from_hash(hash)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# A form object to handle service calendar attributes.
|
|
2
|
+
# It maps boolean attributes (monday, tuesday, etc.) to a weekdays hash to be used by the ServiceCalendar service.
|
|
3
|
+
|
|
4
|
+
module SpreeCmCommissioner::Transit
|
|
5
|
+
class ServiceCalendarForm
|
|
6
|
+
include ActiveModel::Model
|
|
7
|
+
|
|
8
|
+
attr_accessor :name,
|
|
9
|
+
:start_date,
|
|
10
|
+
:end_date,
|
|
11
|
+
:monday,
|
|
12
|
+
:tuesday,
|
|
13
|
+
:wednesday,
|
|
14
|
+
:thursday,
|
|
15
|
+
:friday,
|
|
16
|
+
:saturday,
|
|
17
|
+
:sunday,
|
|
18
|
+
:exception_rules
|
|
19
|
+
|
|
20
|
+
def initialize(attrs = {})
|
|
21
|
+
super
|
|
22
|
+
@exception_rules ||= []
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def weekdays
|
|
26
|
+
{
|
|
27
|
+
'monday' => monday,
|
|
28
|
+
'tuesday' => tuesday,
|
|
29
|
+
'wednesday' => wednesday,
|
|
30
|
+
'thursday' => thursday,
|
|
31
|
+
'friday' => friday,
|
|
32
|
+
'saturday' => saturday,
|
|
33
|
+
'sunday' => sunday
|
|
34
|
+
}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def weekdays=(hash)
|
|
38
|
+
hash = hash.transform_keys(&:to_s)
|
|
39
|
+
@monday = cast_bool(hash['monday'])
|
|
40
|
+
@tuesday = cast_bool(hash['tuesday'])
|
|
41
|
+
@wednesday = cast_bool(hash['wednesday'])
|
|
42
|
+
@thursday = cast_bool(hash['thursday'])
|
|
43
|
+
@friday = cast_bool(hash['friday'])
|
|
44
|
+
@saturday = cast_bool(hash['saturday'])
|
|
45
|
+
@sunday = cast_bool(hash['sunday'])
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
def cast_bool(val)
|
|
51
|
+
ActiveModel::Type::Boolean.new.cast(val)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -12,6 +12,31 @@ module SpreeCmCommissioner::Transit
|
|
|
12
12
|
:trip_stops, # TripStopForm[]
|
|
13
13
|
:service_calendar # monday, tuesday, wednesday, thursday, friday, saturday, sunday, start_date, end_date
|
|
14
14
|
|
|
15
|
+
# Convert params hashes into TripStopForm objects
|
|
16
|
+
def trip_stops_attributes=(arr)
|
|
17
|
+
items = arr.is_a?(Hash) ? arr.values : Array(arr)
|
|
18
|
+
@trip_stops = items.map do |h|
|
|
19
|
+
h = h.to_h.symbolize_keys
|
|
20
|
+
TripStopForm.new.tap do |ts|
|
|
21
|
+
ts.location_id = h[:location_id]
|
|
22
|
+
ts.stop_id = h[:stop_id]
|
|
23
|
+
ts.departure_time = h[:departure_time]
|
|
24
|
+
ts.duration_in_hours = h[:duration_in_hours]
|
|
25
|
+
ts.route_type = h[:route_type]
|
|
26
|
+
ts.vehicle_type_id = h[:vehicle_type_id]
|
|
27
|
+
ts.vehicle_id = h[:vehicle_id]
|
|
28
|
+
ts.board_to_trip_id = h[:board_to_trip_id]
|
|
29
|
+
ts.allow_boarding = h[:allow_boarding]
|
|
30
|
+
ts.allow_drop_off = h[:allow_drop_off]
|
|
31
|
+
ts.allow_seat_selection = h[:allow_seat_selection]
|
|
32
|
+
ts.allow_booking = h[:allow_booking]
|
|
33
|
+
ts.sequence = h[:sequence]
|
|
34
|
+
ts.vendor_id = h[:vendor_id]
|
|
35
|
+
ts.stop_type = h[:stop_type]
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
15
40
|
def multi_leg?
|
|
16
41
|
trip_stops.map(&:location_id).uniq.size > 2
|
|
17
42
|
end
|
|
@@ -46,7 +46,15 @@ module SpreeCmCommissioner::Transit
|
|
|
46
46
|
:sequence,
|
|
47
47
|
#
|
|
48
48
|
# set from create service
|
|
49
|
-
:vendor_id
|
|
49
|
+
:vendor_id,
|
|
50
|
+
# branch or stop
|
|
51
|
+
:stop_type
|
|
52
|
+
|
|
53
|
+
def initialize(options = {})
|
|
54
|
+
options.each do |key, value|
|
|
55
|
+
instance_variable_set("@#{key}", value)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
50
58
|
|
|
51
59
|
def allow_boarding?
|
|
52
60
|
ActiveModel::Type::Boolean.new.cast(allow_boarding)
|
|
@@ -56,10 +64,30 @@ module SpreeCmCommissioner::Transit
|
|
|
56
64
|
ActiveModel::Type::Boolean.new.cast(allow_drop_off)
|
|
57
65
|
end
|
|
58
66
|
|
|
67
|
+
def allow_seat_selection?
|
|
68
|
+
ActiveModel::Type::Boolean.new.cast(allow_seat_selection)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def allow_booking?
|
|
72
|
+
ActiveModel::Type::Boolean.new.cast(allow_booking)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def branch?
|
|
76
|
+
stop_type == 'branch' || stop_type == :branch
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def stop?
|
|
80
|
+
stop_type == 'stop' || stop_type == :stop
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def booking_editable?
|
|
84
|
+
branch? && board_to_trip_id.blank?
|
|
85
|
+
end
|
|
86
|
+
|
|
59
87
|
def duration_in_minutes
|
|
60
88
|
return nil if duration_in_hours.blank?
|
|
61
89
|
|
|
62
|
-
(duration_in_hours.to_f * 60).
|
|
90
|
+
(duration_in_hours.to_f * 60).round
|
|
63
91
|
end
|
|
64
92
|
end
|
|
65
93
|
end
|
|
@@ -27,6 +27,7 @@ require 'spree_cm_commissioner/transit/route_stop'
|
|
|
27
27
|
require 'spree_cm_commissioner/transit/route_stop_collection'
|
|
28
28
|
require 'spree_cm_commissioner/transit/trip_form'
|
|
29
29
|
require 'spree_cm_commissioner/transit/trip_stop_form'
|
|
30
|
+
require 'spree_cm_commissioner/transit/service_calendar_form'
|
|
30
31
|
require 'spree_cm_commissioner/intercity_taxi/map_place'
|
|
31
32
|
require 'spree_cm_commissioner/distance'
|
|
32
33
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: spree_cm_commissioner
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.5.
|
|
4
|
+
version: 2.5.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- You
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-02-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: spree
|
|
@@ -1323,6 +1323,7 @@ files:
|
|
|
1323
1323
|
- app/jobs/spree_cm_commissioner/guests/preload_check_in_session_ids_job.rb
|
|
1324
1324
|
- app/jobs/spree_cm_commissioner/import_order_job.rb
|
|
1325
1325
|
- app/jobs/spree_cm_commissioner/integrations/base_job.rb
|
|
1326
|
+
- app/jobs/spree_cm_commissioner/integrations/cleanup_sync_sessions_job.rb
|
|
1326
1327
|
- app/jobs/spree_cm_commissioner/integrations/polling_job.rb
|
|
1327
1328
|
- app/jobs/spree_cm_commissioner/integrations/polling_scheduler_job.rb
|
|
1328
1329
|
- app/jobs/spree_cm_commissioner/invalidate_cache_request_job.rb
|
|
@@ -2022,6 +2023,7 @@ files:
|
|
|
2022
2023
|
- app/services/spree_cm_commissioner/imports/update_order_service.rb
|
|
2023
2024
|
- app/services/spree_cm_commissioner/integrations/base/sync_manager.rb
|
|
2024
2025
|
- app/services/spree_cm_commissioner/integrations/base/sync_result.rb
|
|
2026
|
+
- app/services/spree_cm_commissioner/integrations/cleanup_sync_sessions.rb
|
|
2025
2027
|
- app/services/spree_cm_commissioner/integrations/polling.rb
|
|
2026
2028
|
- app/services/spree_cm_commissioner/integrations/polling_scheduler.rb
|
|
2027
2029
|
- app/services/spree_cm_commissioner/integrations/stadium_x_v1/external_client/client.rb
|
|
@@ -2048,6 +2050,8 @@ files:
|
|
|
2048
2050
|
- app/services/spree_cm_commissioner/orders/bulk_archive_inactive_orders.rb
|
|
2049
2051
|
- app/services/spree_cm_commissioner/orders/daily_archive_inactive_orders.rb
|
|
2050
2052
|
- app/services/spree_cm_commissioner/orders/generate_commissions_decorator.rb
|
|
2053
|
+
- app/services/spree_cm_commissioner/orders/jwt_token/generate.rb
|
|
2054
|
+
- app/services/spree_cm_commissioner/orders/jwt_token/verify.rb
|
|
2051
2055
|
- app/services/spree_cm_commissioner/organizer/export_guest_csv_service.rb
|
|
2052
2056
|
- app/services/spree_cm_commissioner/organizer/export_invite_guest_csv_service.rb
|
|
2053
2057
|
- app/services/spree_cm_commissioner/payment_method_type_mapper.rb
|
|
@@ -3127,6 +3131,7 @@ files:
|
|
|
3127
3131
|
- lib/spree_cm_commissioner/transit/route_stop.rb
|
|
3128
3132
|
- lib/spree_cm_commissioner/transit/route_stop_collection.rb
|
|
3129
3133
|
- lib/spree_cm_commissioner/transit/seat_selection.rb
|
|
3134
|
+
- lib/spree_cm_commissioner/transit/service_calendar_form.rb
|
|
3130
3135
|
- lib/spree_cm_commissioner/transit/trip_form.rb
|
|
3131
3136
|
- lib/spree_cm_commissioner/transit/trip_stop_form.rb
|
|
3132
3137
|
- lib/spree_cm_commissioner/trip_query_result.rb
|