Fix: Kontakt detail viser nu relaterede firmaer i Firmaer fanen
This commit is contained in:
parent
d2c7a8a624
commit
3628cbd9fe
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user