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}")
|
@router.get("/contacts/{contact_id}")
|
||||||
async def get_contact(contact_id: int):
|
async def get_contact(contact_id: int):
|
||||||
"""Get a single contact by ID"""
|
"""Get a single contact by ID with linked companies"""
|
||||||
try:
|
try:
|
||||||
|
# Get contact info
|
||||||
query = """
|
query = """
|
||||||
SELECT
|
SELECT
|
||||||
id, first_name, last_name, email, phone, mobile,
|
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
|
created_at, updated_at
|
||||||
FROM contacts
|
FROM contacts
|
||||||
WHERE id = %s
|
WHERE id = %s
|
||||||
@ -136,7 +137,23 @@ async def get_contact(contact_id: int):
|
|||||||
if not contacts:
|
if not contacts:
|
||||||
raise HTTPException(status_code=404, detail="Contact not found")
|
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:
|
except HTTPException:
|
||||||
raise
|
raise
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user