Update mappers for flat API response + enrich with property info
All checks were successful
Build frontend / build (push) Successful in 38s
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:
@ -35,35 +35,37 @@ import { getRentProperties, getSaleProperties } from '../utils/api';
|
||||
|
||||
// Map API data to UI format
|
||||
function mapApiProperty(item, index) {
|
||||
const info = item.propertyInformation || item;
|
||||
const info = item.propertyInformation || {};
|
||||
const hasNestedInfo = !!item.propertyInformation;
|
||||
|
||||
const dailyPrice = item.dailyRent ?? item.monthlyRent ?? item.price ?? 0;
|
||||
const monthlyPrice = item.monthlyRent ?? 0;
|
||||
|
||||
const buildingTypeMap = { 0: 'apartment', 1: 'villa', 2: 'house' };
|
||||
const propType = buildingTypeMap[info.buildingType] || 'apartment';
|
||||
const propType = buildingTypeMap[info.buildingType] ?? buildingTypeMap[item.type] ?? 'apartment';
|
||||
|
||||
const statusMap = { 0: 'available', 1: 'booked', 2: 'maintenance' };
|
||||
const status = statusMap[info.status] || 'available';
|
||||
const status = statusMap[info.status] ?? statusMap[item.status] ?? 'available';
|
||||
|
||||
const features = [];
|
||||
if (item.isSmokeAllow) features.push('يسمح بالتدخين');
|
||||
if (item.isVisitorAllow) features.push('يسمح بالزوار');
|
||||
if (info.numberOfRooms) features.push(`${info.numberOfRooms} غرف`);
|
||||
if (item.specializedFor) features.push('متخصص');
|
||||
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) || 'عقار',
|
||||
title: info.address || `عقار #${item.id || index + 1}`,
|
||||
description: info.description || '',
|
||||
type: propType,
|
||||
price: dailyPrice,
|
||||
priceUnit: 'daily',
|
||||
location: {
|
||||
city: extractCity(info.address),
|
||||
city: extractCity(info.address) || 'دمشق',
|
||||
district: info.address || '',
|
||||
},
|
||||
bedrooms: info.numberOfBedRooms || info.numberOfRooms || 0,
|
||||
bedrooms: info.numberOfBedRooms || 0,
|
||||
bathrooms: info.numberOfBathRooms || 0,
|
||||
area: info.space || 0,
|
||||
features,
|
||||
|
||||
Reference in New Issue
Block a user