fixing rolodex and search
This commit is contained in:
@@ -96,7 +96,7 @@ async def search_by_phone(
|
||||
"""Search customers by phone number (legacy phone search feature)"""
|
||||
phones = db.query(Phone).join(Rolodex).filter(
|
||||
Phone.phone.contains(phone)
|
||||
).options(joinedload(Phone.rolodex)).all()
|
||||
).options(joinedload(Phone.rolodex_entry)).all()
|
||||
|
||||
results = []
|
||||
for phone_record in phones:
|
||||
@@ -104,10 +104,10 @@ async def search_by_phone(
|
||||
"phone": phone_record.phone,
|
||||
"location": phone_record.location,
|
||||
"customer": {
|
||||
"id": phone_record.rolodex.id,
|
||||
"name": f"{phone_record.rolodex.first or ''} {phone_record.rolodex.last}".strip(),
|
||||
"city": phone_record.rolodex.city,
|
||||
"state": phone_record.rolodex.abrev
|
||||
"id": phone_record.rolodex_entry.id,
|
||||
"name": f"{phone_record.rolodex_entry.first or ''} {phone_record.rolodex_entry.last}".strip(),
|
||||
"city": phone_record.rolodex_entry.city,
|
||||
"state": phone_record.rolodex_entry.abrev
|
||||
}
|
||||
})
|
||||
|
||||
@@ -178,21 +178,25 @@ async def list_customers(
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""List customers with pagination and search"""
|
||||
query = db.query(Rolodex).options(joinedload(Rolodex.phone_numbers))
|
||||
|
||||
if search:
|
||||
query = query.filter(
|
||||
or_(
|
||||
Rolodex.id.contains(search),
|
||||
Rolodex.last.contains(search),
|
||||
Rolodex.first.contains(search),
|
||||
Rolodex.city.contains(search),
|
||||
Rolodex.email.contains(search)
|
||||
try:
|
||||
query = db.query(Rolodex).options(joinedload(Rolodex.phone_numbers))
|
||||
|
||||
if search:
|
||||
query = query.filter(
|
||||
or_(
|
||||
Rolodex.id.contains(search),
|
||||
Rolodex.last.contains(search),
|
||||
Rolodex.first.contains(search),
|
||||
Rolodex.city.contains(search),
|
||||
Rolodex.email.contains(search)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
customers = query.offset(skip).limit(limit).all()
|
||||
return customers
|
||||
|
||||
customers = query.offset(skip).limit(limit).all()
|
||||
return customers
|
||||
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"Error loading customers: {str(e)}")
|
||||
|
||||
|
||||
@router.get("/{customer_id}", response_model=CustomerResponse)
|
||||
|
||||
Reference in New Issue
Block a user