Module: Ecoportal::API::GraphQL::Helpers::LocationsTree

Included in:
Base::LocationStructure
Defined in:
lib/ecoportal/api/graphql/helpers/locations_tree.rb

Instance Method Summary collapse

Instance Method Details

#treeify(nodes) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/ecoportal/api/graphql/helpers/locations_tree.rb', line 6

def treeify(nodes)
  parents = nodes.each_with_object({}) do |node, parents|
    parent   = node.parent
    parentId = parent && parent.id.upcase
    (parents[parentId] ||= []).push(node)
  end
  get_children(nil, parents)
end