Skip to content

Commit c937908

Browse files
louispt1noracato
authored andcommitted
Expect or convert to array in savedscenario response. No pagination
1 parent 155c9fd commit c937908

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

app/controllers/api/v3/saved_scenarios_controller.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
module 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'] })

0 commit comments

Comments
 (0)