Skip to content

Commit 0288ccb

Browse files
committed
fix(events): Move search filter to post-enrichment stage for accurate results
- Remove search filter from initial database query before data enrichment - Implement search filtering after enriching registrations with profile data - Add support for searching by profile_name in addition to full_name, email, and phone - Update total count calculation to reflect filtered results when search is applied - Improve search accuracy by performing case-insensitive matching on enriched data
1 parent bc2cd18 commit 0288ccb

File tree

1 file changed

+19
-7
lines changed
  • app/api/events/[slug]/registrations

1 file changed

+19
-7
lines changed

app/api/events/[slug]/registrations/route.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@ export async function GET(
9494
query = query.eq('payment_status', paymentStatus);
9595
}
9696

97-
// Apply search (search in full_name, email, phone)
98-
if (search) {
99-
query = query.or(`full_name.ilike.%${search}%,email.ilike.%${search}%,phone.ilike.%${search}%`);
100-
}
101-
10297
// Apply pagination
10398
query = query.range(offset, offset + limit - 1);
10499

@@ -155,9 +150,26 @@ export async function GET(
155150
};
156151
});
157152

153+
// Apply search filter after enrichment (search in profile_name, full_name, email, phone)
154+
let filteredRegistrations = enrichedRegistrations || [];
155+
if (search) {
156+
const searchLower = search.toLowerCase();
157+
filteredRegistrations = filteredRegistrations.filter(reg => {
158+
const profileName = reg.profile_name?.toLowerCase() || '';
159+
const fullName = reg.full_name?.toLowerCase() || '';
160+
const email = reg.email?.toLowerCase() || '';
161+
const phone = reg.phone?.toLowerCase() || '';
162+
163+
return profileName.includes(searchLower) ||
164+
fullName.includes(searchLower) ||
165+
email.includes(searchLower) ||
166+
phone.includes(searchLower);
167+
});
168+
}
169+
158170
return NextResponse.json({
159-
registrations: enrichedRegistrations || [],
160-
total: count || 0,
171+
registrations: filteredRegistrations,
172+
total: search ? filteredRegistrations.length : (count || 0),
161173
event: {
162174
id: event.id,
163175
title: event.title,

0 commit comments

Comments
 (0)