File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,44 +8,32 @@ def index
88 email_param = search_params [ :email ]
99 email_domain = email_param . split ( '@' ) . last if email_param . present? && email_param . include? ( '@' )
1010
11- dummy_orgs = [
12- {
13- id : 'abc123def' ,
14- org_name : 'University of California' ,
15- domain : 'berkeley.edu'
16- } ,
17- {
18- id : 'xyz789ghi' ,
19- org_name : 'Massachusetts Institute of Technology' ,
20- domain : 'mit.edu'
21- } ,
22- {
23- id : 'mno456pqr' ,
24- org_name : 'Stanford University' ,
25- domain : 'stanford.edu'
26- }
27- ]
28-
2911 # Filter orgs by domain if domain parameter is provided
3012 if email_param . present?
31- filtered_orgs = dummy_orgs . select { |org | org [ :domain ] == email_domain }
13+ # filtered_orgs = dummy_orgs.select { |org| org[:domain] == email_domain }
14+ org_results = OrgDomain . search_with_org_info ( email_domain )
15+ result = org_results . map { |record |
16+ {
17+ id : record . id ,
18+ org_name : record . org_name ,
19+ domain : record . domain
20+ }
21+ }
3222
33- # If no matches found, return the "OTHER" org
34- if filtered_orgs . empty?
35- other_org = [
23+ if result . empty?
24+ pattern = "Other"
25+ other_org = Org . where ( "LOWER(orgs.name) = ?" , pattern . downcase )
26+ result = other_org . map { |record |
3627 {
37- ror_id : 'OTHER' ,
38- org_name : 'OTHER' ,
39- domain : 'OTHER'
28+ id : record . id ,
29+ org_name : record . name ,
30+ domain : ""
4031 }
41- ]
42- render json : other_org
43- else
44- render json : filtered_orgs
32+ }
4533 end
34+ render json : result
4635 else
47- # If no domain parameter provided, return all dummy orgs
48- render json : other_org
36+ render json : [ ] , status : :ok
4937 end
5038 end
5139
Original file line number Diff line number Diff line change @@ -88,6 +88,8 @@ class Org < ApplicationRecord
8888
8989 has_many :departments
9090
91+ has_many :org_domains
92+
9193 # ===============
9294 # = Validations =
9395 # ===============
@@ -175,7 +177,6 @@ def check_for_missing_logo_file
175177 6 => :school ,
176178 column : 'org_type' ,
177179 check_for_column : !Rails . env . test?
178-
179180 # The default Org is the one whose guidance is auto-attached to
180181 # plans when a plan is created
181182 def self . default_orgs
Original file line number Diff line number Diff line change 2121class OrgDomain < ApplicationRecord
2222 belongs_to :org
2323
24+ def self . search_with_org_info ( domain )
25+ pattern = "#{ domain . downcase } "
26+ joins ( :org )
27+ . where ( "LOWER(org_domains.domain) = ?" , pattern )
28+ . select ( "orgs.id AS id, orgs.name AS org_name, org_domains.domain" )
29+ end
30+
2431end
You can’t perform that action at this time.
0 commit comments