diff --git a/app/api/profiles/route.ts b/app/api/profiles/route.ts index 2e5dcc64..2965fbee 100644 --- a/app/api/profiles/route.ts +++ b/app/api/profiles/route.ts @@ -6,6 +6,8 @@ export async function GET(request: Request) { const url = new URL(request.url); const page = parseInt(url.searchParams.get("page") || "1"); const gender = url.searchParams.get("gender"); + const minAge = url.searchParams.get("minAge"); + const maxAge = url.searchParams.get("maxAge"); const interests = url.searchParams.get("interests")?.split(",").filter(Boolean) || []; const causeAreas = url.searchParams.get("causeAreas")?.split(",").filter(Boolean) || []; const searchQuery = url.searchParams.get("search") || ""; @@ -28,6 +30,23 @@ export async function GET(request: Request) { }; } + // Add age filtering + const currentYear = new Date().getFullYear(); + if (minAge || maxAge) { + where.profile = { + ...where.profile, + birthYear: {} + }; + + if (minAge) { + where.profile.birthYear.lte = currentYear - parseInt(minAge); + } + + if (maxAge) { + where.profile.birthYear.gte = currentYear - parseInt(maxAge); + } + } + // OR // if (interests.length > 0) { // where.profile = { diff --git a/app/profiles/ProfileFilters.tsx b/app/profiles/ProfileFilters.tsx index cd4cdc7f..6b0d6967 100644 --- a/app/profiles/ProfileFilters.tsx +++ b/app/profiles/ProfileFilters.tsx @@ -9,6 +9,8 @@ interface FilterProps { interests: string[]; causeAreas: string[]; searchQuery: string; + minAge?: number; + maxAge?: number; }; onFilterChange: (key: string, value: any) => void; onShowFilters: (value: boolean) => void; @@ -134,11 +136,35 @@ export function ProfileFilters({filters, onFilterChange, onShowFilters, onToggle ))} +