"""Collaborator model in Neo4j.""" from typing import Tuple from connector_neo4j import get_session from owsresponse import response from account.models.types import ( CollaboratorAttributes as CollaboratorType, CompanyBrand as CompanyBrandType, Vendor as VendorType, ) def get_collaborator_by_uuid( uuid, ) -> Tuple[CollaboratorType, VendorType, CompanyBrandType] | None: """Get Collaborator.""" session = get_session() result = session.run( """ MATCH (v:Vendor)-[:OWNS]->(c:Collaborator { uuid: toString($uuid) }) WITH v, c MATCH (cb:CompanyBrand)-[:HAS_LABEL]->(v) RETURN c,v,cb """, uuid=uuid, ) record = result.single() if not record: return None collaborator = record.data()['c'] vendor = record.data()['v'] company_brand = record.data()['cb'] if not collaborator: return response.create_error_response( 'collaborator_not_found', 'Collaborator Not Found', status=404 ) return ( { 'collaborator_id': collaborator['id'], 'uuid': collaborator['uuid'], 'dp_enabled_date': collaborator.get('dpEnabledDate'), }, { 'vendor_id': vendor['vendorId'], 'uuid': vendor['uuid'], }, { 'id': company_brand['companyBrandId'], 'name': company_brand['name'], }, )