File tree Expand file tree Collapse file tree 2 files changed +28
-7
lines changed
Expand file tree Collapse file tree 2 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -81,15 +81,10 @@ def update # rubocop:disable Metrics/AbcSize
8181 redirect_to aeon_appointments_path , notice : 'Appointment created successfully'
8282 end
8383
84- def destroy # rubocop:disable Metrics/AbcSize
84+ def destroy
8585 authorize! :delete , @appointment
8686
87- @appointment . requests . each do |request |
88- aeon_client . update_request ( request . transaction_number , AeonClient ::DeleteAppointmentRequestData . new )
89- aeon_client . update_request_route ( transaction_number : request . transaction_number ,
90- status : Settings . aeon . queue_names . draft . transaction . first )
91- end
92- aeon_client . cancel_appointment ( params [ :id ] )
87+ CancelAeonAppointmentJob . perform_now ( @appointment )
9388
9489 redirect_to aeon_appointments_path , notice : 'Appointment cancelled successfully'
9590 end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ ##
4+ # Rails Job to submit a hold request to Folio for processing
5+ class CancelAeonAppointmentJob < ApplicationJob
6+ queue_as :default
7+
8+ def perform ( appointment )
9+ appointment . requests . each do |request |
10+ move_request_to_draft ( request )
11+ end
12+ aeon_client . cancel_appointment ( appointment . id )
13+ end
14+
15+ # When an appointment is cancelled, Aeon cancels the requests by default. We want to move them to draft
16+ # and dis-associated the appointment instead.
17+ def move_request_to_draft ( request )
18+ aeon_client . update_request ( request . transaction_number , AeonClient ::DeleteAppointmentRequestData . new )
19+ aeon_client . update_request_route ( transaction_number : request . transaction_number ,
20+ status : Settings . aeon . queue_names . draft . transaction . first )
21+ end
22+
23+ def aeon_client
24+ @aeon_client ||= AeonClient . new
25+ end
26+ end
You can’t perform that action at this time.
0 commit comments