Skip to content

Commit 8c7b773

Browse files
author
John Pinto
committed
Added code to OrgDomainController so 'Other' org is returned in result array in index method.
1 parent e614aeb commit 8c7b773

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

app/controllers/org_domain_controller.rb

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,28 @@ def index
2424
}
2525

2626
unless result.empty?
27+
# Add Other org to end of array
28+
result << other_org_json
2729
puts "result: #{result}"
2830
render json: result, status: :ok
2931
return
3032
end
31-
33+
3234
# if org doesn't exist already call Orion API by passing domain
3335
begin
3436
full_org_json = ::ExternalApis::OrionService.search_by_domain(email_domain)
3537
puts "full_org_json: #{full_org_json}"
3638

3739
unless full_org_json&.key?('orgs')
3840
puts 'Invalid response or no orgs key found'
39-
other_org = Org.find_other_org
40-
org_id_new_format = {id: other_org.id, name: other_org.name}.to_json
41-
result = [{
42-
id: org_id_new_format,
43-
org_name: other_org.name,
44-
domain: ''
45-
}]
41+
# Add Other org
42+
result = [other_org_json]
4643
render json: result, status: :ok
4744
return
4845
end
4946

5047
# Extract the values from API result
51-
result = full_org_json['orgs'].map do |org|
48+
result = full_org_json['orgs'].map do |org|
5249
title = org['names'].find { |n| n['types'].include?('ror_display') }
5350
# ror_id_formatted = org['id'].split('/').last
5451
org_id_new_format = {name: title['value']}.to_json
@@ -59,19 +56,12 @@ def index
5956
}
6057
rescue => e
6158
puts "Failed request: #{e.message}"
59+
# If the request fails, log the error and return an empty array
6260
result = []
6361
end
6462

65-
# if no org exists - assign to org called 'Other'
66-
if result.blank?
67-
other_org = Org.find_other_org
68-
org_id_new_format = {id: other_org.id, name: other_org.org_name}.to_json
69-
result = [{
70-
id: org_id_new_format,
71-
org_name: other_org.name,
72-
domain: ''
73-
}]
74-
end
63+
# Add Other org to end of array.
64+
result << other_org_json
7565
end
7666
render json: result, status: :ok
7767
end
@@ -122,5 +112,15 @@ def search_params
122112
def org_domain_params
123113
params.require(:org_domain).permit(:domain)
124114
end
115+
116+
def other_org_json
117+
other_org = Org.find_other_org
118+
org_id_new_format = { id: other_org.id, name: other_org.name }.to_json
119+
{
120+
id: org_id_new_format,
121+
org_name: other_org.name,
122+
domain: "",
123+
}
124+
end
125125
end
126126

0 commit comments

Comments
 (0)