Skip to content

Commit 92b081a

Browse files
restricted search in events page in dashboard to notification_id, request_id, client_id and client_name
1 parent 2f8ffbe commit 92b081a

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

dashboard/app/api/notifications/route.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,16 @@ export async function GET(request: NextRequest) {
4747
}
4848

4949
if (search) {
50+
// Search only indexed fields for performance
5051
filter.$or = [
5152
{ request_id: { $regex: search, $options: 'i' } },
52-
{ 'recipient.email': { $regex: search, $options: 'i' } },
53-
{ 'recipient.phone': { $regex: search, $options: 'i' } },
54-
{ 'recipient.user_id': { $regex: search, $options: 'i' } },
55-
{ client_id: { $regex: search, $options: 'i' } }
53+
{ client_id: { $regex: search, $options: 'i' } },
54+
{ client_name: { $regex: search, $options: 'i' } }
5655
];
56+
// Also search by notification ID if it looks like a valid ObjectId
57+
if (/^[a-f0-9]{24}$/i.test(search)) {
58+
filter.$or.push({ _id: search } as any);
59+
}
5760
}
5861

5962
if (from || to) {

dashboard/app/events/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export default function EventsPage() {
116116
<PageToolbar className="flex-col sm:flex-row gap-3">
117117
<PageToolbarSection className="w-full sm:w-auto sm:flex-1 sm:max-w-md">
118118
<Input
119-
placeholder="Search by request ID, recipient..."
119+
placeholder="Search by notification ID, request ID, client ID/name..."
120120
value={searchInput}
121121
onChange={(e) => setSearchInput(e.target.value)}
122122
onKeyDown={handleKeyDown}

0 commit comments

Comments
 (0)