Fix email routing and contact search
This commit is contained in:
parent
592ed8640d
commit
5f2452f222
@ -88,8 +88,26 @@ async def get_contacts(
|
|||||||
params = []
|
params = []
|
||||||
|
|
||||||
if search:
|
if search:
|
||||||
where_clauses.append("(c.first_name ILIKE %s OR c.last_name ILIKE %s OR c.email ILIKE %s)")
|
where_clauses.append(
|
||||||
params.extend([f"%{search}%", f"%{search}%", f"%{search}%"])
|
"""
|
||||||
|
(
|
||||||
|
c.first_name ILIKE %s
|
||||||
|
OR c.last_name ILIKE %s
|
||||||
|
OR c.email ILIKE %s
|
||||||
|
OR c.phone ILIKE %s
|
||||||
|
OR c.mobile ILIKE %s
|
||||||
|
OR EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM contact_companies cc2
|
||||||
|
JOIN customers cu2 ON cu2.id = cc2.customer_id
|
||||||
|
WHERE cc2.contact_id = c.id
|
||||||
|
AND cu2.name ILIKE %s
|
||||||
|
)
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
like = f"%{search}%"
|
||||||
|
params.extend([like, like, like, like, like, like])
|
||||||
|
|
||||||
if is_active is not None:
|
if is_active is not None:
|
||||||
where_clauses.append("c.is_active = %s")
|
where_clauses.append("c.is_active = %s")
|
||||||
|
|||||||
@ -113,8 +113,27 @@ async def get_contacts(
|
|||||||
params = []
|
params = []
|
||||||
|
|
||||||
if search:
|
if search:
|
||||||
where_clauses.append("(c.first_name ILIKE %s OR c.last_name ILIKE %s OR c.email ILIKE %s)")
|
where_clauses.append(
|
||||||
params.extend([f"%{search}%", f"%{search}%", f"%{search}%"])
|
"""
|
||||||
|
(
|
||||||
|
c.first_name ILIKE %s
|
||||||
|
OR c.last_name ILIKE %s
|
||||||
|
OR c.email ILIKE %s
|
||||||
|
OR c.phone ILIKE %s
|
||||||
|
OR c.mobile ILIKE %s
|
||||||
|
OR c.user_company ILIKE %s
|
||||||
|
OR EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM contact_companies cc2
|
||||||
|
JOIN customers cu2 ON cu2.id = cc2.customer_id
|
||||||
|
WHERE cc2.contact_id = c.id
|
||||||
|
AND cu2.name ILIKE %s
|
||||||
|
)
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
like = f"%{search}%"
|
||||||
|
params.extend([like, like, like, like, like, like, like])
|
||||||
|
|
||||||
if is_active is not None:
|
if is_active is not None:
|
||||||
where_clauses.append("c.is_active = %s")
|
where_clauses.append("c.is_active = %s")
|
||||||
|
|||||||
@ -953,7 +953,7 @@ async function loadContacts() {
|
|||||||
totalContacts = data.total;
|
totalContacts = data.total;
|
||||||
currentContactsData = Array.isArray(data.contacts) ? data.contacts : [];
|
currentContactsData = Array.isArray(data.contacts) ? data.contacts : [];
|
||||||
displayContacts(currentContactsData);
|
displayContacts(currentContactsData);
|
||||||
updatePagination(data.total);
|
updatePagination(data.total, currentContactsData.length);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.name === 'AbortError') {
|
if (error.name === 'AbortError') {
|
||||||
@ -1182,11 +1182,12 @@ function persistTablePreferences() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updatePagination(total) {
|
function updatePagination(total, rowsOnPage = 0) {
|
||||||
const start = currentPage * pageSize + 1;
|
const safeRowsOnPage = Number.isFinite(Number(rowsOnPage)) ? Math.max(0, Number(rowsOnPage)) : 0;
|
||||||
const end = Math.min((currentPage + 1) * pageSize, total);
|
const start = total > 0 ? (currentPage * pageSize + 1) : 0;
|
||||||
|
const end = total > 0 ? Math.min(currentPage * pageSize + safeRowsOnPage, total) : 0;
|
||||||
|
|
||||||
document.getElementById('showingStart').textContent = total > 0 ? start : 0;
|
document.getElementById('showingStart').textContent = start;
|
||||||
document.getElementById('showingEnd').textContent = end;
|
document.getElementById('showingEnd').textContent = end;
|
||||||
document.getElementById('totalCount').textContent = total;
|
document.getElementById('totalCount').textContent = total;
|
||||||
|
|
||||||
|
|||||||
@ -1156,11 +1156,13 @@ class EmailWorkflowService:
|
|||||||
if sag_id_from_tag:
|
if sag_id_from_tag:
|
||||||
if sag_id and sag_id != sag_id_from_tag:
|
if sag_id and sag_id != sag_id_from_tag:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"⚠️ Email %s contains conflicting case hints (thread: SAG-%s, tag: SAG-%s). Using thread match.",
|
"⚠️ Email %s contains conflicting case hints (thread: SAG-%s, tag: SAG-%s). Using SAG tag.",
|
||||||
email_id,
|
email_id,
|
||||||
sag_id,
|
sag_id,
|
||||||
sag_id_from_tag
|
sag_id_from_tag
|
||||||
)
|
)
|
||||||
|
sag_id = sag_id_from_tag
|
||||||
|
routing_source = 'sag_tag'
|
||||||
elif not sag_id:
|
elif not sag_id:
|
||||||
sag_id = sag_id_from_tag
|
sag_id = sag_id_from_tag
|
||||||
routing_source = 'sag_tag'
|
routing_source = 'sag_tag'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user