added the descption
All checks were successful
Build frontend / build (push) Successful in 43s

This commit is contained in:
mouazkh
2026-05-26 18:22:21 +03:00
parent 3f24696c48
commit bf044cef45

View File

@ -161,6 +161,7 @@ function mapApiDetail(item) {
isSmokeAllow: item.isSmokeAllow,
isVisitorAllow: item.isVisitorAllow,
specializedFor: item.specializedFor,
ownerId: item.userId || item.ownerId || info.userId || info.ownerId || null,
_raw: item,
};
}
@ -221,30 +222,43 @@ export default function PropertyDetailsPage() {
}
}
// Check if current user owns this property
if (AuthService.isAuthenticated() && AuthService.isOwner()) {
try {
const [myRent, mySale] = await Promise.allSettled([
getMyRentListings(),
getMySaleListings(),
]);
const myPropIds = new Set();
const collectIds = (result) => {
if (result.status !== 'fulfilled' || !result.value) return;
const list = Array.isArray(result.value) ? result.value : [result.value];
list.forEach(p => {
const info = p.propertyInformation || {};
if (info.id) myPropIds.add(Number(info.id));
if (p.id) myPropIds.add(Number(p.id));
});
};
collectIds(myRent);
collectIds(mySale);
const checkId = Number(mapped.id) || mapped.id;
const checkInfoId = Number(mapped._raw?.propertyInformation?.id) || mapped._raw?.propertyInformation?.id;
if (myPropIds.has(checkId) || (checkInfoId && myPropIds.has(checkInfoId))) {
setIsOwnProperty(true);
}
} catch {}
if (AuthService.isAuthenticated()) {
const currentUserId = AuthService.getUserId();
const raw = mapped._raw || {};
const rawInfo = raw.propertyInformation || {};
console.log('[OwnerCheck] currentUserId:', currentUserId);
console.log('[OwnerCheck] raw keys:', Object.keys(raw));
console.log('[OwnerCheck] rawInfo keys:', Object.keys(rawInfo));
console.log('[OwnerCheck] raw.userId:', raw.userId, 'raw.ownerId:', raw.ownerId, 'rawInfo.userId:', rawInfo.userId, 'rawInfo.ownerId:', rawInfo.ownerId);
const possibleOwnerFields = [raw.userId, raw.ownerId, rawInfo.userId, rawInfo.ownerId, raw.userID, raw.ownerID, rawInfo.userID, rawInfo.ownerID].filter(Boolean);
if (possibleOwnerFields.some(id => String(id) === String(currentUserId))) {
setIsOwnProperty(true);
} else if (AuthService.isOwner()) {
try {
const [myRent, mySale] = await Promise.allSettled([
getMyRentListings(),
getMySaleListings(),
]);
const myPropIds = new Set();
const collectIds = (result) => {
if (result.status !== 'fulfilled' || !result.value) return;
const list = Array.isArray(result.value) ? result.value : [result.value];
list.forEach(p => {
const info = p.propertyInformation || {};
if (info.id) myPropIds.add(Number(info.id));
if (p.id) myPropIds.add(Number(p.id));
});
};
collectIds(myRent);
collectIds(mySale);
const checkId = mapped.id ? Number(mapped.id) : null;
const checkInfoId = rawInfo.id ? Number(rawInfo.id) : null;
console.log('[OwnerCheck] myPropIds:', [...myPropIds], 'checkId:', checkId, 'checkInfoId:', checkInfoId);
if ((checkId && myPropIds.has(checkId)) || (checkInfoId && myPropIds.has(checkInfoId))) {
setIsOwnProperty(true);
}
} catch (e) { console.error('[OwnerCheck] fallback error:', e); }
}
}
}
} catch (err) {