mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
adding ability to add more filters
This commit is contained in:
parent
c87826fa7a
commit
d5d4a4cc27
2 changed files with 13 additions and 2 deletions
|
|
@ -74,7 +74,8 @@ export default async function Page(props: {
|
|||
const properties: PropertyWithRelations[] = await getProperties(
|
||||
portfolioId,
|
||||
1000,
|
||||
0
|
||||
0,
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -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<PropertyWithRelations[]> {
|
||||
// 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<PropertyWithRelations>(sql<PropertyWithRelations>`
|
||||
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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue