File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed
Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change 33module Api
44 module V3
55 class SavedScenariosController < BaseController
6- render json :
76
87 before_action ( only : %i[ index show ] ) do
98 authorize! ( :read , @scenario )
@@ -14,13 +13,15 @@ class SavedScenariosController < BaseController
1413 end
1514
1615 def index
17- query = { page : params [ :page ] , limit : params [ :limit ] } . compact . to_query
16+ query = { page : params [ :page ] , limit : params [ :limit ] } . compact . to_query
1817 response = my_etm_client . get ( "/api/v1/saved_scenarios?#{ query } " )
1918
20- render json : response . body . to_h . merge (
21- 'data' => hydrate_scenarios ( response . body [ 'data' ] ) ,
22- 'links' => update_pagination_links ( response . body [ 'links' ] )
23- )
19+ data = response . body . is_a? ( Array ) ? response . body : response . body [ 'data' ] || [ ]
20+
21+ render json : {
22+ data : hydrate_scenarios ( data ) ,
23+ links : { }
24+ }
2425 end
2526
2627 def show
@@ -72,6 +73,8 @@ def destroy
7273 private
7374
7475 def hydrate_scenarios ( saved_scenarios )
76+ saved_scenarios = saved_scenarios . is_a? ( Array ) ? saved_scenarios : [ saved_scenarios ]
77+
7578 scenarios = Scenario
7679 . accessible_by ( current_ability )
7780 . where ( id : saved_scenarios . map { |s | s [ 'scenario_id' ] } )
You can’t perform that action at this time.
0 commit comments