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,