Update mappers for flat API response + enrich with property info
All checks were successful
Build frontend / build (push) Successful in 38s

- api.js: getRentProperties/getSaleProperties now fetch PropertyInformation
  for each property's propInfoId (when Properties/Get endpoint is fixed)
- Updated all 3 mapApiProperty functions to handle flat response format
  (no nested propertyInformation) - uses defaults for missing fields
- Status/type mapping checks both flat and nested fields
This commit is contained in:
Claw AI
2026-03-26 22:59:08 +00:00
parent bdcb98a047
commit fd3dcf4cc3
4 changed files with 92 additions and 37 deletions

View File

@ -31,46 +31,47 @@ 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
function mapApiProperty(item, index) {
const info = item.propertyInformation || item;
const isRent = item.monthlyRent !== undefined || item.dailyRent !== undefined;
const info = item.propertyInformation || {};
const hasNestedInfo = !!item.propertyInformation;
// Determine price display
const dailyPrice = item.dailyRent ?? item.monthlyRent ?? item.price ?? 0;
const monthlyPrice = item.monthlyRent ?? 0;
// Map building type integer to string
// BuildingType: 0=Apartment, 1=Villa, 2=House
const buildingTypeMap = { 0: 'apartment', 1: 'villa', 2: 'house' };
const propType = buildingTypeMap[info.buildingType] || 'apartment';
const propType = buildingTypeMap[info.buildingType] ?? buildingTypeMap[item.type] ?? 'apartment';
// Map property status integer to string
// Status: 0=Available, 1=Booked, 2=Maintenance
const statusMap = { 0: 'available', 1: 'booked', 2: 'maintenance' };
const status = statusMap[info.status] || 'available';
const status = statusMap[info.status] ?? statusMap[item.status] ?? 'available';
// Extract features as string array
const features = [];
if (item.isSmokeAllow) features.push('يسمح بالتدخين');
if (item.isVisitorAllow) features.push('يسمح بالزوار');
if (item.specializedFor) features.push('متخصص');
if (info.numberOfRooms) features.push(`${info.numberOfRooms} غرف`);
if (info.numberOfBedRooms) features.push(`${info.numberOfBedRooms} غرف نوم`);
if (info.numberOfBathRooms) features.push(`${info.numberOfBathRooms} حمامات`);
return {
id: item.id ?? index + 1,
title: info.address || info.description?.substring(0, 40) || 'عقار',
propInfoId: item.propInfoId,
title: info.address || `عقار #${item.id || index + 1}`,
description: info.description || '',
type: propType,
price: dailyPrice,
priceUSD: dailyPrice,
priceUnit: 'daily',
location: {
city: extractCity(info.address),
city: extractCity(info.address) || 'دمشق',
district: info.address || '',
address: info.address || '',
lat: parseFloat(info.cordsX) || 0,
lng: parseFloat(info.cordsY) || 0,
},
bedrooms: info.numberOfBedRooms || info.numberOfRooms || 0,
bedrooms: info.numberOfBedRooms || 0,
bathrooms: info.numberOfBathRooms || 0,
area: info.space || 0,
features,
@ -94,7 +95,7 @@ function extractCity(address) {
for (const city of cities) {
if (address.includes(city)) return city;
}
return address.split(' ').pop() || '';
return '';
}
// Fallback dummy data