"""Model layer for graph based resource queries.""" from connector_neo4j import get_session from owsresponse import response from notifications.utils.neo4j import strip_query def get_resource_name(resource_type: str, resource_uuid: str) -> response.Response: """Get the name of a resource by its type and uuid. Args: resource_type (str): The type of tenant. See TenantType enum. resource_uuid (str): The uuid of the tenant. """ session = get_session() query = f""" MATCH (resource:{resource_type}) WHERE resource.uuid = $resource_uuid RETURN resource.name AS resource_name LIMIT 1 """ result = session.run(strip_query(query), resource_uuid=resource_uuid).single() if not result: return response.create_not_found_response( f'No {resource_type} found with uuid {resource_uuid}.' ) return response.Response(result.get('resource_name'))