diff --git a/app/page.js b/app/page.js index dc91195..e5e7cd4 100644 --- a/app/page.js +++ b/app/page.js @@ -31,11 +31,9 @@ import Image from 'next/image'; import { getRentProperties, getSaleProperties } from './utils/api'; // Map API property data to the format the UI expects -// API returns { propInfoId, deposit, monthlyRent, dailyRent, rating, ... } -// If propertyInformation is nested, use it; otherwise use flat response with defaults +// API returns { propertyInformationId, deposit, monthlyRent, dailyRent, rating, propertyInformation: {...}, ... } function mapApiProperty(item, index) { const info = item.propertyInformation || {}; - const hasNestedInfo = !!item.propertyInformation; const dailyPrice = item.dailyRent ?? item.monthlyRent ?? item.price ?? 0; const monthlyPrice = item.monthlyRent ?? 0; @@ -57,7 +55,6 @@ function mapApiProperty(item, index) { return { id: item.id ?? index + 1, - propInfoId: item.propInfoId, title: info.address || `عقار #${item.id || index + 1}`, description: info.description || '', type: propType, diff --git a/app/properties/page.js b/app/properties/page.js index bfee996..21aca29 100644 --- a/app/properties/page.js +++ b/app/properties/page.js @@ -36,7 +36,6 @@ import { getRentProperties, getSaleProperties } from '../utils/api'; // Map API data to UI format function mapApiProperty(item, index) { const info = item.propertyInformation || {}; - const hasNestedInfo = !!item.propertyInformation; const dailyPrice = item.dailyRent ?? item.monthlyRent ?? item.price ?? 0; const monthlyPrice = item.monthlyRent ?? 0; diff --git a/app/property/[id]/page.js b/app/property/[id]/page.js index 5d477c4..fdfe2e2 100644 --- a/app/property/[id]/page.js +++ b/app/property/[id]/page.js @@ -49,7 +49,6 @@ function mapApiDetail(item) { if (!item) return null; const info = item.propertyInformation || {}; - const hasNestedInfo = !!item.propertyInformation; const dailyPrice = item.dailyRent ?? item.monthlyRent ?? item.price ?? 0; const monthlyPrice = item.monthlyRent ?? 0; diff --git a/app/utils/api.js b/app/utils/api.js index 2ff3a7c..94cad88 100644 --- a/app/utils/api.js +++ b/app/utils/api.js @@ -37,39 +37,13 @@ async function apiFetch(endpoint, options = {}) { // ─── Rent Properties ─── export async function getRentProperties() { - const rentList = await apiFetch('/RentProperties/GetRentProperties'); - if (!Array.isArray(rentList) || rentList.length === 0) return rentList; - - // Fetch property info for each rent property's propInfoId - const enriched = await Promise.all( - rentList.map(async (item) => { - try { - const propInfo = await apiFetch(`/Properties/Get/${item.propInfoId}`); - return { ...item, propertyInformation: propInfo }; - } catch { - return item; - } - }) - ); - return enriched; + return apiFetch('/RentProperties/GetRentProperties'); } export async function getRentProperty(id) { - const item = await apiFetch(`/RentProperties/GetRentProperties?id=${id}`); - if (!item) return item; - - // If it's an array (all results), pick the matching one - const property = Array.isArray(item) ? item.find(p => p.id == id) || item[0] : item; - - if (property?.propInfoId) { - try { - const propInfo = await apiFetch(`/Properties/Get/${property.propInfoId}`); - return { ...property, propertyInformation: propInfo }; - } catch { - // ignore - } - } - return property; + const items = await apiFetch('/RentProperties/GetRentProperties'); + if (!Array.isArray(items)) return items; + return items.find(p => p.id == id) || items[0]; } export async function getRentPropertyLocations(params = {}) { @@ -83,35 +57,13 @@ export async function getRentPropertyLocations(params = {}) { // ─── Sale Properties ─── export async function getSaleProperties() { - const saleList = await apiFetch('/SaleProperties/GetSaleProperties'); - if (!Array.isArray(saleList) || saleList.length === 0) return saleList; - - const enriched = await Promise.all( - saleList.map(async (item) => { - try { - const propInfo = await apiFetch(`/Properties/Get/${item.propInfoId}`); - return { ...item, propertyInformation: propInfo }; - } catch { - return item; - } - }) - ); - return enriched; + return apiFetch('/SaleProperties/GetSaleProperties'); } export async function getSaleProperty(id) { - const item = await apiFetch(`/SaleProperties/GetSaleProperties?id=${id}`); - const property = Array.isArray(item) ? item.find(p => p.id == id) || item[0] : item; - - if (property?.propInfoId) { - try { - const propInfo = await apiFetch(`/Properties/Get/${property.propInfoId}`); - return { ...property, propertyInformation: propInfo }; - } catch { - // ignore - } - } - return property; + const items = await apiFetch('/SaleProperties/GetSaleProperties'); + if (!Array.isArray(items)) return items; + return items.find(p => p.id == id) || items[0]; } // ─── Properties (generic) ───