From bf044cef45772a0a3eeed6507d490577429e744b Mon Sep 17 00:00:00 2001 From: mouazkh Date: Tue, 26 May 2026 18:22:21 +0300 Subject: [PATCH] added the descption --- app/property/[id]/PropertyDetail.js | 62 ++++++++++++++++++----------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/app/property/[id]/PropertyDetail.js b/app/property/[id]/PropertyDetail.js index fccfaf6..f3f13ac 100644 --- a/app/property/[id]/PropertyDetail.js +++ b/app/property/[id]/PropertyDetail.js @@ -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) {