From c4fd797e31e3d7be50522b79443fc3af886d8e33 Mon Sep 17 00:00:00 2001 From: paritosh18 Date: Wed, 25 Feb 2026 14:48:54 +0530 Subject: [PATCH] change the nearby logic --- src/modules/user/services/user.service.ts | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/modules/user/services/user.service.ts b/src/modules/user/services/user.service.ts index a54663b..34f993f 100644 --- a/src/modules/user/services/user.service.ts +++ b/src/modules/user/services/user.service.ts @@ -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,