diff --git a/app/listings/actions.ts b/app/listings/actions.ts
index 8f1d1728..ca4e9c77 100644
--- a/app/listings/actions.ts
+++ b/app/listings/actions.ts
@@ -1,7 +1,8 @@
"use server";
import prisma from "@/lib/db";
-import { Listing, PrismaListing } from "./types";
+import { DEFAULT_LIST_FILTERS } from "./constants";
+import { Listing, ListingsSearchFilters, PrismaListing } from "./types";
const prismaListingMapper = (dbListing: PrismaListing) => {
const dbListingPrice = dbListing.prices
@@ -30,13 +31,47 @@ const prismaListingMapper = (dbListing: PrismaListing) => {
return listing;
};
-export async function fetchMatchedListings(): Promise
{
- // TODO: Add filter param values
+export async function fetchMatchedListings(
+ filters: ListingsSearchFilters = DEFAULT_LIST_FILTERS
+): Promise {
+ // TODO: Use beds filter values
+ // TODO: Use baths filter values
const prismaListings = await prisma.listing.findMany({
include: {
address: true,
prices: true,
},
+ where: {
+ // Filter (price)
+ prices: {
+ some: {
+ // Price must be current ...
+ isCurrent: true,
+ AND: {
+ // ... and must be greater than or equal than the minimum filter value ...
+ value: {
+ gte: filters.price.min.value,
+ },
+ AND: {
+ // ... and must be lesser than or equal than the maximum filter value
+ value: {
+ lte: filters.price.max.value,
+ },
+ },
+ },
+ },
+ },
+ // Filter (area): must be greater than or equal than the minimum filter value ...
+ area: {
+ gte: filters.area.min.value,
+ },
+ AND: {
+ // ... and must be lesser than or equal than the maximum filter value
+ area: {
+ lte: filters.area.max.value,
+ },
+ },
+ },
});
return prismaListings.map(prismaListingMapper);
}
diff --git a/app/listings/constants.ts b/app/listings/constants.ts
index f4ed31dd..f2c8d234 100644
--- a/app/listings/constants.ts
+++ b/app/listings/constants.ts
@@ -4,7 +4,7 @@ export const LISTINGS_PER_PAGE = 15;
export const STARTING_PAGE = 1;
const PRICE_MIN_FILTER = 0;
-const PRICE_MAX_FILTER = 10_000_000;
+const PRICE_MAX_FILTER = 100_000_000;
/**
* These are the labels for the beds/baths filter
* The values to be used is its index.
diff --git a/app/listings/page.tsx b/app/listings/page.tsx
index 365a5dbb..7ece9da9 100644
--- a/app/listings/page.tsx
+++ b/app/listings/page.tsx
@@ -4,7 +4,6 @@ import ListingsProvider from "./provider";
import { ListingsSearchFilters } from "./search-filters";
export default async function Listings() {
- // TODO: Use default filter values, import them from constants.tsx file
const listings = await fetchMatchedListings();
return (