From 3628cbd9fe61ca18a563ed84429fc5812b7db28a Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 22 Dec 2025 16:40:49 +0100 Subject: [PATCH] Fix: Kontakt detail viser nu relaterede firmaer i Firmaer fanen --- app/contacts/backend/router_simple.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/app/contacts/backend/router_simple.py b/app/contacts/backend/router_simple.py index c45fbc1..002ee8c 100644 --- a/app/contacts/backend/router_simple.py +++ b/app/contacts/backend/router_simple.py @@ -121,12 +121,13 @@ async def get_contacts( @router.get("/contacts/{contact_id}") async def get_contact(contact_id: int): - """Get a single contact by ID""" + """Get a single contact by ID with linked companies""" try: + # Get contact info query = """ SELECT id, first_name, last_name, email, phone, mobile, - title, department, is_active, user_company, + title, department, is_active, user_company, vtiger_id, created_at, updated_at FROM contacts WHERE id = %s @@ -136,7 +137,23 @@ async def get_contact(contact_id: int): if not contacts: raise HTTPException(status_code=404, detail="Contact not found") - return contacts[0] + contact = contacts[0] + + # Get linked companies + companies_query = """ + SELECT + cu.id, cu.name, cu.cvr_number, + cc.is_primary, cc.role, cc.notes + FROM contact_companies cc + JOIN customers cu ON cc.customer_id = cu.id + WHERE cc.contact_id = %s + ORDER BY cc.is_primary DESC, cu.name + """ + companies = execute_query(companies_query, (contact_id,)) + + contact['companies'] = companies or [] + + return contact except HTTPException: raise