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

@ -48,47 +48,47 @@ import { getRentProperty, getSaleProperty, bookReservation, checkAvailability }
function mapApiDetail(item) {
if (!item) return null;
const info = item.propertyInformation || item;
const isRent = item.monthlyRent !== undefined || item.dailyRent !== undefined;
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';
// Build features array
const features = [];
if (item.isSmokeAllow) features.push({ name: 'يسمح بالتدخين', available: true, description: '' });
if (item.isVisitorAllow) features.push({ name: 'يسمح بالزوار', available: true, description: '' });
if (item.specializedFor) features.push({ name: 'متخصص', available: true, description: '' });
if (info.numberOfBedRooms) features.push({ name: 'غرف النوم', available: true, description: `${info.numberOfBedRooms} غرف` });
if (info.numberOfBathRooms) features.push({ name: 'الحمامات', available: true, description: `${info.numberOfBathRooms} حمامات` });
if (info.space) features.push({ name: 'المساحة', available: true, description: `${info.space} م²` });
const typeLabels = { 0: 'شقة', 1: 'فيلا', 2: 'بيت' };
return {
id: item.id,
title: info.address || info.description?.substring(0, 50) || `عقار #${item.id}`,
description: info.description || '',
title: info.address || `عقار #${item.id}`,
description: info.description || 'عقار سكني مميز في موقع استراتيجي.',
type: propType,
price: dailyPrice,
priceUnit: isRent ? 'daily' : 'sale',
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: features.length > 0 ? features : [
{ name: 'غرف نوم', available: true, description: `${info.numberOfBedRooms || 0} غرف` },
{ name: 'حمامات', available: true, description: `${info.numberOfBathRooms || 0} حمامات` },
{ name: 'المساحة', available: true, description: `${info.space || 0} م²` },
{ name: 'متاح للإيجار', available: true, description: '' },
],
images: ['/property-placeholder.jpg', '/villa1.jpg', '/villa2.jpg'],
status,