From d5d4a4cc2758f3f0d8b7dc7974bfdab9a4f91172 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Mon, 8 Dec 2025 13:53:11 +0000 Subject: [PATCH] adding ability to add more filters --- src/app/portfolio/[slug]/(portfolio)/page.tsx | 3 ++- src/app/portfolio/[slug]/utils.ts | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/app/portfolio/[slug]/(portfolio)/page.tsx b/src/app/portfolio/[slug]/(portfolio)/page.tsx index a41a972..51a8bcb 100644 --- a/src/app/portfolio/[slug]/(portfolio)/page.tsx +++ b/src/app/portfolio/[slug]/(portfolio)/page.tsx @@ -74,7 +74,8 @@ export default async function Page(props: { const properties: PropertyWithRelations[] = await getProperties( portfolioId, 1000, - 0 + 0, + [] ); return ( diff --git a/src/app/portfolio/[slug]/utils.ts b/src/app/portfolio/[slug]/utils.ts index 9850739..3cdd5af 100644 --- a/src/app/portfolio/[slug]/utils.ts +++ b/src/app/portfolio/[slug]/utils.ts @@ -19,6 +19,7 @@ import { ScenarioSelect, } from "@/app/db/schema/recommendations"; import { sql } from "drizzle-orm"; +import { PropertyFilter } from "@/app/utils/propertyFilters"; export interface PortfolioSettingsType { name: string; @@ -416,10 +417,18 @@ export async function getNonDefaultPortfolioScenarios( export async function getProperties( portfolioId: string, limit: number = 1000, - offset: number = 0 + offset: number = 0, + filters: PropertyFilter[] = [] ): Promise { // We need to perform the query like this because the nested query is not supported in the ORM right now + const whereClauses: any[] = []; + + const combinedWhere = + whereClauses.length > 0 + ? sql`AND (${sql.join(whereClauses, sql` AND `)})` + : sql``; + const result = await db.execute(sql` SELECT @@ -450,6 +459,7 @@ export async function getProperties( ON r.id = pr.recommendation_id AND r.default = true WHERE p.portfolio_id = ${portfolioId} + ${combinedWhere} GROUP BY p.id, p.portfolio_id,