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

@ -37,11 +37,39 @@ async function apiFetch(endpoint, options = {}) {
// ─── Rent Properties ───
export async function getRentProperties() {
return apiFetch('/RentProperties/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;
}
export async function getRentProperty(id) {
return apiFetch(`/RentProperties/GetRentProperties?id=${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;
}
export async function getRentPropertyLocations(params = {}) {
@ -55,11 +83,35 @@ export async function getRentPropertyLocations(params = {}) {
// ─── Sale Properties ───
export async function getSaleProperties() {
return apiFetch('/SaleProperties/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;
}
export async function getSaleProperty(id) {
return apiFetch(`/SaleProperties/GetSaleProperties?id=${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;
}
// ─── Properties (generic) ───