sending the latestactivity image in the bucket

This commit is contained in:
2026-03-10 21:30:43 +05:30
parent 00e07113e5
commit b5cdb20c4f
3 changed files with 88 additions and 50 deletions

View File

@@ -66,6 +66,8 @@ export const handler = safeHandler(async (
data: {
bucketCount: counts.bucketCount,
interestedCount: counts.interestedCount,
coverImage: counts.coverImage,
coverImagePresignedUrl: counts.coverImagePresignedUrl,
}
}),
};

View File

@@ -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 {

View File

@@ -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',
},
},
};
}