@@ -52,9 +52,9 @@ def number_of_places
5252 #
5353 # Returns:
5454 # an array of Place objects
55- def places_near ( location , distance = nil , limit = nil , snac = nil )
55+ def places_near ( location , distance = nil , limit = nil , snac = [ ] )
5656 query = places
57- query = query . where ( snac : snac ) if snac
57+ query = query . where ( :snac . in => snac ) if snac . any?
5858 query = query . limit ( limit ) if limit
5959 query = query . geo_near ( [ location . longitude , location . latitude ] )
6060 query = query . max_distance ( distance . in ( :degrees ) ) if distance
@@ -73,23 +73,23 @@ def places_for_postcode(postcode, distance = nil, limit = nil)
7373 # involve some frontend work though. For now, do this to
7474 # match the existing (not totally correct) behaviour
7575 snac = appropriate_snac_for_postcode ( postcode )
76- return [ ] unless snac
76+ return [ ] unless snac . any?
7777
7878 places_near ( location , distance , limit , snac )
7979 end
8080
8181 def appropriate_snac_for_postcode ( postcode )
8282 local_custodian_codes = GdsApi . locations_api . local_custodian_code_for_postcode ( postcode )
83- return nil if local_custodian_codes . compact . empty?
83+ return [ ] if local_custodian_codes . compact . empty?
8484
8585 local_authorities_response = GdsApi . local_links_manager . local_authority_by_custodian_code ( local_custodian_codes . first )
8686 filtered_authorities = local_authorities_response . to_hash [ "local_authorities" ] . select do |la |
87- [ service . local_authority_hierarchy_match_type , "unitary" ] . include? ( la [ "tier" ] )
87+ service . local_authority_hierarchy_match_type == Service :: LOCAL_AUTHORITY_EITHER_MATCH || [ service . local_authority_hierarchy_match_type , "unitary" ] . include? ( la [ "tier" ] )
8888 end
8989
90- filtered_authorities . first &. dig ( "snac" ) # there should be 0-1, return nil or first snac
90+ filtered_authorities . map { | a | a [ " snac" ] }
9191 rescue GdsApi ::HTTPNotFound
92- nil
92+ [ ]
9393 end
9494
9595 def duplicating?
0 commit comments