diff --git a/app/property/[id]/PropertyDetail.js b/app/property/[id]/PropertyDetail.js index f3f13ac..3736955 100644 --- a/app/property/[id]/PropertyDetail.js +++ b/app/property/[id]/PropertyDetail.js @@ -161,7 +161,7 @@ function mapApiDetail(item) { isSmokeAllow: item.isSmokeAllow, isVisitorAllow: item.isVisitorAllow, specializedFor: item.specializedFor, - ownerId: item.userId || item.ownerId || info.userId || info.ownerId || null, + ownerId: info.ownerId ?? info.userId ?? item.ownerId ?? item.userId ?? null, _raw: item, }; } @@ -221,19 +221,18 @@ export default function PropertyDetailsPage() { console.warn('Failed to fetch date ranges', e); } } - // Check if current user owns this property + // Check if current user owns this property (Flutter approach) if (AuthService.isAuthenticated()) { const currentUserId = AuthService.getUserId(); - const raw = mapped._raw || {}; - const rawInfo = raw.propertyInformation || {}; + const rawInfo = (mapped._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))) { + console.log('[OwnerCheck] mapped.ownerId:', mapped.ownerId, 'rawInfo.ownerId:', rawInfo.ownerId); + // Check 1: Direct ownerId match (like Flutter: property.ownerId == currentUserId) + if (mapped.ownerId != null && currentUserId != null && Number(mapped.ownerId) === Number(currentUserId)) { setIsOwnProperty(true); - } else if (AuthService.isOwner()) { + } + // Check 2: ManagedPropertiesService fallback (owner only) + else if (AuthService.isOwner()) { try { const [myRent, mySale] = await Promise.allSettled([ getMyRentListings(), @@ -253,7 +252,6 @@ export default function PropertyDetailsPage() { 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); } @@ -815,6 +813,17 @@ export default function PropertyDetailsPage() { {/* Sidebar */}
isOwnProperty: {String(isOwnProperty)}
+ownerId: {String(property.ownerId ?? 'null')}
+rawInfo keys: {Object.keys((property._raw||{}).propertyInformation||{}).join(', ') || 'none'}
+