Now update the threads endpoint:


Edit

        case 'threads':
            $contactId = (int)($_GET['contact'] ?? 0);
            $search = trim($_GET['search'] ?? '');
            $page = max(1, (int)($_GET['page'] ?? 1));
            $limit = min(100, max(1, (int)($_GET['limit'] ?? 20)));
            $offset = ($page - 1) * $limit;
            $hasBusiness = isset($_GET['has_business']) && $_GET['has_business'];

            // Use QueryAdapter for automatic MySQL/MongoDB routing
            $adapter = QueryAdapter::getInstance();
            $result = $adapter->getThreads(
                $contactId ?: null,
                $search,
                $limit,
                $offset
            );

        case 'threads':
            $contactId = (int)($_GET['contact'] ?? 0);
            $search = trim($_GET['search'] ?? '');
            $page = max(1, (int)($_GET['page'] ?? 1));
            $limit = min(100, max(1, (int)($_GET['limit'] ?? 20)));
            $offset = ($page - 1) * $limit;
            $hasBusiness = isset($_GET['has_business']) && $_GET['has_business'];
            $threadSort = $_GET['sort'] ?? 'last_date';
            $threadOrder = strtoupper($_GET['order'] ?? 'DESC') === 'ASC' ? 'ASC' : 'DESC';
            $threadContactName = trim($_GET['contact_name'] ?? '');
            $threadDateFrom = $_GET['date_from'] ?? '';
            $threadDateTo = $_GET['date_to'] ?? '';
            $threadStatus = $_GET['status'] ?? '';

            // Use QueryAdapter for automatic MySQL/MongoDB routing
            $adapter = QueryAdapter::getInstance();
            $result = $adapter->getThreads(
                $contactId ?: null,
                $search,
                $limit,
                $offset,
                $threadSort,
                $threadOrder,
                $threadContactName,
                $threadDateFrom,
                $threadDateTo,
                $threadStatus
            );