Übersicht der Kontakte

Dieser Commit ist enthalten in:
2025-06-19 17:59:50 +02:00
Ursprung 0e79e5ed57
Commit 9e5843afcf
5 geänderte Dateien mit 291 neuen und 2 gelöschten Zeilen

Datei anzeigen

@@ -295,4 +295,36 @@ class LeadRepository:
deleted = cur.rowcount > 0
cur.close()
return deleted
return deleted
def get_all_contacts_with_institutions(self) -> List[Dict[str, Any]]:
"""Get all contacts with their institution information"""
with self.get_db_connection() as conn:
cur = conn.cursor(cursor_factory=RealDictCursor)
query = """
SELECT
c.id,
c.first_name,
c.last_name,
c.position,
c.created_at,
c.updated_at,
c.institution_id,
i.name as institution_name,
(SELECT COUNT(*) FROM lead_contact_details
WHERE contact_id = c.id AND detail_type = 'phone') as phone_count,
(SELECT COUNT(*) FROM lead_contact_details
WHERE contact_id = c.id AND detail_type = 'email') as email_count,
(SELECT COUNT(*) FROM lead_notes
WHERE contact_id = c.id AND is_current = true) as note_count
FROM lead_contacts c
JOIN lead_institutions i ON i.id = c.institution_id
ORDER BY c.last_name, c.first_name
"""
cur.execute(query)
results = cur.fetchall()
cur.close()
return results