diff --git a/src/modules/user/handlers/activities/addToBucketInterested.ts b/src/modules/user/handlers/activities/addToBucketInterested.ts index baf980d..f600a6e 100644 --- a/src/modules/user/handlers/activities/addToBucketInterested.ts +++ b/src/modules/user/handlers/activities/addToBucketInterested.ts @@ -66,6 +66,8 @@ export const handler = safeHandler(async ( data: { bucketCount: counts.bucketCount, interestedCount: counts.interestedCount, + coverImage: counts.coverImage, + coverImagePresignedUrl: counts.coverImagePresignedUrl, } }), }; diff --git a/src/modules/user/handlers/activities/getSpecificSearchApi.ts b/src/modules/user/handlers/activities/getSpecificSearchApi.ts index cf61f4f..275fb95 100644 --- a/src/modules/user/handlers/activities/getSpecificSearchApi.ts +++ b/src/modules/user/handlers/activities/getSpecificSearchApi.ts @@ -26,19 +26,11 @@ export const handler = safeHandler(async ( } // Extract query parameters for search - const activityTitle = event.queryStringParameters?.activityTitle?.trim(); const activityType = event.queryStringParameters?.activityType?.trim(); - const checkInCity = event.queryStringParameters?.checkInCity?.trim(); - - // At least one search parameter should be provided - if (!activityTitle && !activityType && !checkInCity) { - throw new ApiError(400, 'At least one search parameter (activityTitle, activityType, or checkInCity) must be provided'); - } // Fetch activities based on search criteria const result = await userService.searchActivities( - userId, - { activityTitle, activityType, checkInCity } + activityType ); return { diff --git a/src/modules/user/services/user.service.ts b/src/modules/user/services/user.service.ts index edf6629..841f44b 100644 --- a/src/modules/user/services/user.service.ts +++ b/src/modules/user/services/user.service.ts @@ -770,6 +770,52 @@ export class UserService { u => u.activityXid, ); + const latestUserActivity = await tx.userBucketInterested.findFirst({ + where: { + userXid: userId, + isActive: true, + }, + orderBy: { + createdAt: 'desc', + }, + select: { + activityXid: true, + }, + }); + + let latestCoverImage: string | null = null; + let latestCoverImagePresignedUrl: string | null = null; + + if (latestUserActivity) { + const latestActivityImage = await tx.activities.findFirst({ + where: { + id: latestUserActivity.activityXid, + isActive: true, + activityInternalStatus: ACTIVITY_INTERNAL_STATUS.ACTIVITY_LISTED, + amInternalStatus: ACTIVITY_AM_INTERNAL_STATUS.ACTIVITY_LISTED, + }, + select: { + ActivitiesMedia: { + where: { + isCoverImage: true, + isActive: true, + }, + select: { + mediaFileName: true, + }, + take: 1, + }, + }, + }); + + latestCoverImage = + latestActivityImage?.ActivitiesMedia?.[0]?.mediaFileName ?? null; + + latestCoverImagePresignedUrl = latestCoverImage + ? await attachPresignedUrl(latestCoverImage) + : null; + } + const userConnectionDetails = await tx.connectDetails.findMany({ where: { userXid: userId, isActive: true }, select: { @@ -1273,6 +1319,9 @@ export class UserService { loggedInNetworkCount: 0, citiesInNetworkCount: 0, rating: 0, + latestBucketInterestedCoverImage: latestCoverImage, + latestBucketInterestedCoverImagePresignedUrl: + latestCoverImagePresignedUrl, interestedCount: userInterestedActivityIds.length, bucketCount: userBucketActivityIds.length, pagination: { @@ -2426,6 +2475,7 @@ export class UserService { isActive: true, user: { isActive: true, + profileImage: { not: null }, }, }, select: { @@ -2435,29 +2485,35 @@ export class UserService { }, }, }, + take: 5, }); const randomFive = interestedUsers .sort(() => Math.random() - 0.5) .slice(0, 5); - const interestedUserImages: { profileImage: string }[] = []; + // const interestedUserImages: { profileImage: string }[] = []; - for (const item of randomFive) { - const profileImage = item.user.profileImage; + // for (const item of randomFive) { + // const profileImage = item.user.profileImage; - if (profileImage) { - const key = profileImage.startsWith('http') - ? new URL(profileImage).pathname.replace(/^\/+/, '') - : profileImage; + // if (profileImage) { + // const key = profileImage.startsWith('http') + // ? new URL(profileImage).pathname.replace(/^\/+/, '') + // : profileImage; - const presignedUrl = await getPresignedUrl(bucket, key); + // const presignedUrl = await getPresignedUrl(bucket, key); - interestedUserImages.push({ - profileImage: presignedUrl, - }); - } - } + // interestedUserImages.push({ + // profileImage: presignedUrl, + // }); + // } + // } + const interestedUserImages = await Promise.all( + randomFive.map(async ({ user }) => ({ + profileImage: await attachPresignedUrl(user.profileImage), + })) + ); const checkInLocation = activity?.checkInCity?.cityName && activity?.checkInState?.stateName @@ -2488,46 +2544,34 @@ export class UserService { async searchActivities( - userId: number, - searchCriteria: { - activityTitle?: string; - activityType?: string; - checkInCity?: string; - }, + activityType?: string ) { - const { activityTitle, activityType, checkInCity } = searchCriteria; // Build the where clause dynamically const where: any = { isActive: true, activityInternalStatus: ACTIVITY_INTERNAL_STATUS.ACTIVITY_LISTED, amInternalStatus: ACTIVITY_AM_INTERNAL_STATUS.ACTIVITY_LISTED, + ...(activityType && { + activityType: { + is: { + activityTypeName: { + contains: activityType, + mode: 'insensitive', + }, + }, + }, + }), }; - // Add activityTitle filter if provided - if (activityTitle) { - where.activityTitle = { - contains: activityTitle, - mode: 'insensitive', - }; - } - // Add activityType filter if provided if (activityType) { where.activityType = { - activityTypeName: { - contains: activityType, - mode: 'insensitive', - }, - }; - } - - // Add checkInCity filter if provided - if (checkInCity) { - where.checkInCity = { - cityName: { - contains: checkInCity, - mode: 'insensitive', + is: { + activityTypeName: { + contains: activityType, + mode: 'insensitive', + }, }, }; }