sending the isBukcet and isInterested flag in getbyid api and changed the logic in the getactivitiesfrom connections api
This commit is contained in:
@@ -2027,6 +2027,21 @@ export class UserService {
|
||||
throw new Error("Activity not found");
|
||||
}
|
||||
|
||||
const userActivityStatus = await tx.userBucketInterested.findFirst({
|
||||
where: {
|
||||
activityXid: activityXid,
|
||||
userXid: userId,
|
||||
isActive: true,
|
||||
},
|
||||
select: {
|
||||
isBucket: true,
|
||||
},
|
||||
});
|
||||
|
||||
const isBucket = userActivityStatus?.isBucket === true;
|
||||
const isInterested =
|
||||
userActivityStatus ? userActivityStatus.isBucket === false : false;
|
||||
|
||||
const userLocation = await tx.userAddressDetails.findFirst({
|
||||
where: { userXid: userId },
|
||||
select: {
|
||||
@@ -2228,7 +2243,9 @@ export class UserService {
|
||||
totalCapacity,
|
||||
rating: 0, // ⭐ Placeholder, implement rating logic as needed
|
||||
distance: distance || 0,
|
||||
interestedUserImages
|
||||
interestedUserImages,
|
||||
isBucket,
|
||||
isInterested
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -2636,7 +2653,7 @@ export class UserService {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
isSchool: true,
|
||||
isActive: true,
|
||||
createdAt: true,
|
||||
@@ -2762,37 +2779,9 @@ export class UserService {
|
||||
) {
|
||||
const data = await this.prisma.$transaction(async (tx) => {
|
||||
|
||||
const networkUsers = await tx.connectDetails.findMany({
|
||||
const userInterests = await tx.userInterests.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
schoolCompanyXid: {
|
||||
in: schoolCompanyXids,
|
||||
},
|
||||
userXid: {
|
||||
not: userId,
|
||||
},
|
||||
},
|
||||
select: {
|
||||
userXid: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
if (!networkUsers.length) {
|
||||
return {
|
||||
interests: [],
|
||||
mostHypedActivities: null,
|
||||
newArrivalsActivities: null,
|
||||
otherStatesActivities: null,
|
||||
overSeasActivities: null,
|
||||
};
|
||||
}
|
||||
|
||||
const networkUserIds = [...new Set(networkUsers.map(u => u.userXid))];
|
||||
|
||||
const networkUserInterests = await tx.userInterests.findMany({
|
||||
where: {
|
||||
userXid: { in: networkUserIds },
|
||||
userXid: userId,
|
||||
isActive: true,
|
||||
},
|
||||
distinct: ['interestXid'],
|
||||
@@ -2810,9 +2799,74 @@ export class UserService {
|
||||
}
|
||||
});
|
||||
|
||||
const distinctInterests = networkUserInterests.map(i => i.interestXid);
|
||||
if (!userInterests.length) {
|
||||
return {
|
||||
interests: [],
|
||||
mostHypedActivities: null,
|
||||
newArrivalsActivities: null,
|
||||
otherStatesActivities: null,
|
||||
overSeasActivities: null,
|
||||
};
|
||||
}
|
||||
|
||||
if (!distinctInterests.length) {
|
||||
const connectionUsers = await tx.connectDetails.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
schoolCompanyXid: { in: schoolCompanyXids },
|
||||
userXid: { not: userId },
|
||||
},
|
||||
select: {
|
||||
userXid: true,
|
||||
},
|
||||
});
|
||||
|
||||
const connectionUserIds = [
|
||||
...new Set(connectionUsers.map((u) => u.userXid)),
|
||||
];
|
||||
|
||||
const connectionInterestByActivity = await tx.userBucketInterested.groupBy({
|
||||
by: ["activityXid"],
|
||||
where: {
|
||||
userXid: { in: connectionUserIds },
|
||||
isActive: true,
|
||||
},
|
||||
_count: {
|
||||
activityXid: true,
|
||||
},
|
||||
});
|
||||
|
||||
const connectionInterestMap = new Map(
|
||||
connectionInterestByActivity.map((item) => [
|
||||
item.activityXid,
|
||||
item._count.activityXid,
|
||||
])
|
||||
);
|
||||
|
||||
if (!connectionUserIds.length) {
|
||||
return {
|
||||
interests: [],
|
||||
mostHypedActivities: null,
|
||||
newArrivalsActivities: null,
|
||||
otherStatesActivities: null,
|
||||
overSeasActivities: null,
|
||||
};
|
||||
}
|
||||
|
||||
const connectionActivities = await tx.userBucketInterested.findMany({
|
||||
where: {
|
||||
userXid: { in: connectionUserIds },
|
||||
isActive: true,
|
||||
},
|
||||
select: {
|
||||
activityXid: true,
|
||||
},
|
||||
});
|
||||
|
||||
const connectionActivityIds = [
|
||||
...new Set(connectionActivities.map((a) => a.activityXid)),
|
||||
];
|
||||
|
||||
if (!connectionActivityIds.length) {
|
||||
return {
|
||||
interests: [],
|
||||
mostHypedActivities: null,
|
||||
@@ -2825,7 +2879,7 @@ export class UserService {
|
||||
const activityTypes = await tx.activityTypes.findMany({
|
||||
where: {
|
||||
interestXid: {
|
||||
in: distinctInterests,
|
||||
in: userInterests.map(i => i.interestXid),
|
||||
},
|
||||
isActive: true,
|
||||
},
|
||||
@@ -2842,6 +2896,8 @@ export class UserService {
|
||||
};
|
||||
}
|
||||
|
||||
const activityTypeIds = activityTypes.map((a) => a.id);
|
||||
|
||||
const userAddressDetails = await tx.userAddressDetails.findFirst({
|
||||
where: { userXid: userId },
|
||||
select: {
|
||||
@@ -2881,42 +2937,6 @@ export class UserService {
|
||||
const effectiveCountryXid = effectiveLocation?.countryXid ?? null;
|
||||
const effectiveStateXid = effectiveLocation?.stateXid ?? null;
|
||||
|
||||
const userConnectionDetails = await tx.connectDetails.findMany({
|
||||
where: { userXid: userId, isActive: true },
|
||||
select: {
|
||||
id: true,
|
||||
schoolCompanyXid: true,
|
||||
}
|
||||
})
|
||||
|
||||
const otherConnectionUsers = await tx.connectDetails.findMany({
|
||||
where: { userXid: { notIn: [userId] }, isActive: true, schoolCompanyXid: { in: userConnectionDetails.map((u) => u.schoolCompanyXid) } },
|
||||
select: {
|
||||
id: true,
|
||||
userXid: true,
|
||||
}
|
||||
})
|
||||
|
||||
const connectionUserIds = otherConnectionUsers.map(u => u.userXid);
|
||||
|
||||
const connectionInterestByActivity = await tx.userBucketInterested.groupBy({
|
||||
by: ['activityXid'],
|
||||
where: {
|
||||
userXid: { in: connectionUserIds },
|
||||
isActive: true,
|
||||
},
|
||||
_count: {
|
||||
activityXid: true,
|
||||
},
|
||||
});
|
||||
|
||||
const connectionInterestMap = new Map(
|
||||
connectionInterestByActivity.map(item => [
|
||||
item.activityXid,
|
||||
item._count.activityXid,
|
||||
])
|
||||
);
|
||||
|
||||
const userBucketInterested = await tx.userBucketInterested.findMany({
|
||||
where: {
|
||||
userXid: userId,
|
||||
@@ -2942,12 +2962,11 @@ export class UserService {
|
||||
// Reverted to simple ID based sorting for Interest-based activities
|
||||
const activities = await tx.activities.findMany({
|
||||
where: {
|
||||
id: { in: connectionActivityIds }, // 🔥 NEW FILTER
|
||||
isActive: true,
|
||||
activityInternalStatus: ACTIVITY_INTERNAL_STATUS.ACTIVITY_LISTED,
|
||||
amInternalStatus: ACTIVITY_AM_INTERNAL_STATUS.ACTIVITY_LISTED,
|
||||
activityTypeXid: {
|
||||
in: activityTypes.map(at => at.id),
|
||||
},
|
||||
activityTypeXid: { in: activityTypeIds },
|
||||
},
|
||||
skip,
|
||||
take: limit,
|
||||
@@ -2992,14 +3011,13 @@ export class UserService {
|
||||
},
|
||||
});
|
||||
|
||||
const activityTypeIds = activityTypes.map(a => a.id);
|
||||
|
||||
const mostHypedTotalCount = await tx.userBucketInterested.groupBy({
|
||||
by: ['activityXid'],
|
||||
where: {
|
||||
isActive: true,
|
||||
isBucket: false,
|
||||
Activities: {
|
||||
id: { in: connectionActivityIds },
|
||||
activityTypeXid: { in: activityTypeIds },
|
||||
isActive: true,
|
||||
activityInternalStatus: ACTIVITY_INTERNAL_STATUS.ACTIVITY_LISTED,
|
||||
@@ -3019,6 +3037,7 @@ export class UserService {
|
||||
isActive: true,
|
||||
isBucket: false,
|
||||
Activities: {
|
||||
id: { in: connectionActivityIds },
|
||||
activityTypeXid: { in: activityTypeIds },
|
||||
isActive: true,
|
||||
activityInternalStatus: ACTIVITY_INTERNAL_STATUS.ACTIVITY_LISTED,
|
||||
@@ -3153,6 +3172,7 @@ export class UserService {
|
||||
3️⃣ NEW ARRIVALS (RANKED)
|
||||
===================================================== */
|
||||
const newArrivalsWhere = {
|
||||
id: { in: connectionActivityIds },
|
||||
isActive: true,
|
||||
activityInternalStatus: ACTIVITY_INTERNAL_STATUS.ACTIVITY_LISTED,
|
||||
amInternalStatus: ACTIVITY_AM_INTERNAL_STATUS.ACTIVITY_LISTED,
|
||||
@@ -3166,6 +3186,7 @@ export class UserService {
|
||||
4️⃣ OTHER STATES ACTIVITIES (RANKED)
|
||||
===================================================== */
|
||||
const otherStatesWhere: any = {
|
||||
id: { in: connectionActivityIds },
|
||||
isActive: true,
|
||||
activityInternalStatus: ACTIVITY_INTERNAL_STATUS.ACTIVITY_LISTED,
|
||||
amInternalStatus: ACTIVITY_AM_INTERNAL_STATUS.ACTIVITY_LISTED,
|
||||
@@ -3186,6 +3207,7 @@ export class UserService {
|
||||
5️⃣ OVERSEAS ACTIVITIES (RANKED)
|
||||
===================================================== */
|
||||
const overseasWhere: any = {
|
||||
id: { in: connectionActivityIds },
|
||||
isActive: true,
|
||||
activityInternalStatus: ACTIVITY_INTERNAL_STATUS.ACTIVITY_LISTED,
|
||||
amInternalStatus: ACTIVITY_AM_INTERNAL_STATUS.ACTIVITY_LISTED,
|
||||
@@ -3238,7 +3260,7 @@ export class UserService {
|
||||
);
|
||||
|
||||
const interestsWithActivities = await Promise.all(
|
||||
networkUserInterests
|
||||
userInterests
|
||||
.sort((a, b) =>
|
||||
a.interest.interestName.localeCompare(b.interest.interestName)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user