lib/masterfiles/repositories/location_repo.rb
# Given a location id, find its parent of a particular location type.
Given a location id, find its parent of a particular location type.
Given a location id find its parent of a particular location type .
def find_parent_of_type(location_type_code, location_id)
      query = <<~SQL
        SELECT l.id
        FROM tree_locations t
        JOIN locations l ON l.id = t.ancestor_location_id AND l.location_type_id = (SELECT id from location_types WHERE location_type_code = ?)
        WHERE t.descendant_location_id = ?
      SQL
      id = DB[query, location_type_code, location_id].get(:id)
      return failed_response(%(No "#{location_type_code}" found for location "#{location_id}")) if id.nil?
      success_response('ok', id)
    end
def find_parent_of_type ( location_type_code , location_id ) query = <<~SQL 
        SELECT l.id
        FROM tree_locations t
        JOIN locations l ON l.id = t.ancestor_location_id AND l.location_type_id = (SELECT id from location_types WHERE location_type_code = ?)
        WHERE t.descendant_location_id = ?
       SQL id = DB [ query , location_type_code , location_id ] . get ( :id ) return failed_response ( %(No "#{location_type_code}" found for location "#{location_id}") ) if id . nil? success_response ( 'ok' , id ) end
Given a location id, find its parent of a particular location type.
Given a location id find its parent of a particular location type .
location_type_code
<not_specific>
location_id
<not_specific>