change the nearby logic

This commit is contained in:
paritosh18
2026-02-25 14:48:54 +05:30
parent 3f96dd4ae1
commit c4fd797e31

View File

@@ -1896,6 +1896,39 @@ export class UserService {
const skip = (page - 1) * limit;
// 0⃣ Get user's interests and map to activity types
const userInterests = await this.prisma.userInterests.findMany({
where: { userXid: userId, isActive: true },
select: { interestXid: true },
});
if (!userInterests.length) {
return {
page,
limit,
totalCount: 0,
hasMore: false,
activities: [],
};
}
const activityTypeIds = (
await this.prisma.activityTypes.findMany({
where: { interestXid: { in: userInterests.map((u) => u.interestXid) }, isActive: true },
select: { id: true },
})
).map((t) => t.id);
if (!activityTypeIds.length) {
return {
page,
limit,
totalCount: 0,
hasMore: false,
activities: [],
};
}
// Rough bounding box in degrees to reduce DB scan
const earthRadiusKm = 6371;
const latDelta = (radiusKm / earthRadiusKm) * (180 / Math.PI);
@@ -1908,6 +1941,7 @@ export class UserService {
isActive: true,
activityInternalStatus: ACTIVITY_INTERNAL_STATUS.ACTIVITY_LISTED,
amInternalStatus: ACTIVITY_AM_INTERNAL_STATUS.ACTIVITY_LISTED,
activityTypeXid: { in: activityTypeIds },
checkInLat: {
not: null,
gte: userLat - latDelta,