From 343d2b2ab878c8a4b7cd71ffa366f4e8b716c105 Mon Sep 17 00:00:00 2001 From: casulit Date: Wed, 30 Oct 2024 13:29:05 +0800 Subject: [PATCH] feat(server): Add price range filter to properties API endpoint --- server.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server.ts b/server.ts index a9a0ae4..bc5695e 100644 --- a/server.ts +++ b/server.ts @@ -35,6 +35,8 @@ app.get("/api/properties", async (c: Context) => { no_of_bathrooms_max?: string; no_of_parking_spaces_min?: string; no_of_parking_spaces_max?: string; + price_min?: string; + price_max?: string; ai_generated_description?: string; sort_by?: string; sort_order?: string; @@ -133,6 +135,15 @@ app.get("/api/properties", async (c: Context) => { ); } + // Add price range condition if both min and max are provided + if (query.price_min && query.price_max) { + addWhereCondition( + `l.price BETWEEN $${paramCounter} AND $${paramCounter + 1}`, + parseFloat(query.price_min), + parseFloat(query.price_max), + ); + } + // Add building size range condition if both min and max are provided if (query.building_size_min && query.building_size_max) { addWhereCondition(