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