From 4772c320ba976c040b16cbda87e9719338ec90a6 Mon Sep 17 00:00:00 2001 From: Mayank Mishra Date: Tue, 2 Dec 2025 17:53:19 +0530 Subject: [PATCH 1/4] Enhance HostService and MinglarService to include account manager details and process profile images. Updated getAllHostActivity to retrieve account manager information and generate presigned URLs for media and profile images. Refactored media processing logic for improved clarity and consistency. --- src/modules/host/services/host.service.ts | 85 ++++++++++++++++++- .../minglaradmin/services/minglar.service.ts | 42 +++++---- 2 files changed, 105 insertions(+), 22 deletions(-) diff --git a/src/modules/host/services/host.service.ts b/src/modules/host/services/host.service.ts index f3cfa84..d97d0f9 100644 --- a/src/modules/host/services/host.service.ts +++ b/src/modules/host/services/host.service.ts @@ -102,6 +102,17 @@ export class HostService { documentType: true, }, }, + accountManager: { + select: { + id: true, + firstName: true, + lastName: true, + emailAddress: true, + mobileNumber: true, + profileImage: true, + userRefNumber: true, + } + }, user: { select: { id: true, @@ -177,6 +188,14 @@ export class HostService { host.logoPath = await getPresignedUrl(bucket, key); } + if (host.accountManager.profileImage) { + const key = host.accountManager.profileImage.startsWith('http') + ? host.accountManager.profileImage.split('.com/')[1] + : host.accountManager.profileImage; + + host.accountManager.profileImage = await getPresignedUrl(bucket, key); + } + if (host.hostParent?.length) { const parent = host.hostParent[0]; // since you allow only 1 parent @@ -354,18 +373,76 @@ export class HostService { }); } - async getAllHostActivity(search?: string, hostXid?: number) { - return await this.prisma.activities.findMany({ + async getAllHostActivity(search?: string, user_xid?: number) { + const hostDetails = await this.prisma.hostHeader.findFirst({ + where: { userXid: user_xid, isActive: true } + }) + + const hostAllActivities = await this.prisma.activities.findMany({ where: { isActive: true, - hostXid: hostXid, + hostXid: hostDetails.id, }, include: { ActivitiesMedia: true, - ActivityAmDetails: true, + ActivityAmDetails: { + select: { + accountManager: { + select: { + id: true, + firstName: true, + lastName: true, + profileImage: true, + emailAddress: true, + roleXid: true, + }, + }, + }, + }, activityType: true, }, }); + + for (const activity of hostAllActivities) { + + /** 1️⃣ Process Activity Media */ + const processedMedia = []; + + for (const media of activity.ActivitiesMedia || []) { + + const key = media.mediaFileName?.startsWith("http") + ? media.mediaFileName.split(".com/")[1] + : media.mediaFileName; + + const presignedUrl = key ? await getPresignedUrl(bucket, key) : null; + + processedMedia.push({ + ...media, + presignedUrl, + }); + } + + activity.ActivitiesMedia = processedMedia; + + /** 2️⃣ Process AM Profile Image */ + const am = activity.ActivityAmDetails?.[0]?.accountManager; + + if (am?.profileImage) { + const key = am.profileImage.startsWith("http") + ? am.profileImage.split(".com/")[1] + : am.profileImage; + + const presignedUrl = await getPresignedUrl(bucket, key); + + activity.ActivityAmDetails[0].accountManager = { + ...am, + profileImage: presignedUrl, + }; + } + } + + + return hostAllActivities; } async acceptMinglarAgreement(user_xid: number) { diff --git a/src/modules/minglaradmin/services/minglar.service.ts b/src/modules/minglaradmin/services/minglar.service.ts index bfc543b..f4f25cd 100644 --- a/src/modules/minglaradmin/services/minglar.service.ts +++ b/src/modules/minglaradmin/services/minglar.service.ts @@ -291,26 +291,26 @@ export class MinglarService { // Process each activity for (const activity of hostActivities) { - /** -------------------------- - * 1️⃣ Process Activity Media - * -------------------------- */ - if (activity.ActivitiesMedia?.length) { - for (const media of activity.ActivitiesMedia) { + /** 1️⃣ Process Activity Media */ + const processedMedia = []; - if (!media.mediaFileName) continue; + for (const media of activity.ActivitiesMedia || []) { - // Extract S3 key if URL or keep raw key - const key = media.mediaFileName.startsWith("http") - ? media.mediaFileName.split(".com/")[1] - : media.mediaFileName; + const key = media.mediaFileName?.startsWith("http") + ? media.mediaFileName.split(".com/")[1] + : media.mediaFileName; - media.mediaFileName = await getPresignedUrl(bucket, key); - } + const presignedUrl = key ? await getPresignedUrl(bucket, key) : null; + + processedMedia.push({ + ...media, + presignedUrl, + }); } - /** -------------------------- - * 2️⃣ Process AM Profile Image - * -------------------------- */ + activity.ActivitiesMedia = processedMedia; + + /** 2️⃣ Process AM Profile Image */ const am = activity.ActivityAmDetails?.[0]?.accountManager; if (am?.profileImage) { @@ -318,10 +318,16 @@ export class MinglarService { ? am.profileImage.split(".com/")[1] : am.profileImage; - am.profileImage = await getPresignedUrl(bucket, key); + const presignedUrl = await getPresignedUrl(bucket, key); + + activity.ActivityAmDetails[0].accountManager = { + ...am, + profileImage: presignedUrl, + }; } } + return hostActivities; } @@ -1645,9 +1651,9 @@ export class MinglarService { isActive: true }, data: { - activityInternalStatus: ACTIVITY_INTERNAL_STATUS.PQQ_TO_UPDATE, + activityInternalStatus: ACTIVITY_INTERNAL_STATUS.PQ_TO_UPDATE, activityDisplayStatus: ACTIVITY_DISPLAY_STATUS.ENHANCING, - amInternalStatus: ACTIVITY_AM_INTERNAL_STATUS.PQQ_REJECTED, + amInternalStatus: ACTIVITY_AM_INTERNAL_STATUS.PQ_REJECTED, amDisplayStatus: ACTIVITY_AM_DISPLAY_STATUS.ENHANCING } }) From d9f7cd9a0fcf5c91f1f9577fe4e00da6c42c21a0 Mon Sep 17 00:00:00 2001 From: Mayank Mishra Date: Tue, 2 Dec 2025 18:08:39 +0530 Subject: [PATCH 2/4] fixed the optional chaining --- src/modules/host/services/host.service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/host/services/host.service.ts b/src/modules/host/services/host.service.ts index d97d0f9..0794b04 100644 --- a/src/modules/host/services/host.service.ts +++ b/src/modules/host/services/host.service.ts @@ -172,7 +172,7 @@ export class HostService { } } } - if (host.user.profileImage) { + if (host.user?.profileImage) { const key = host.user.profileImage.startsWith("http") ? host.user.profileImage.split(".com/")[1] : host.user.profileImage; @@ -180,7 +180,7 @@ export class HostService { host.user.profileImage = await getPresignedUrl(bucket, key); } - if (host.logoPath) { + if (host?.logoPath) { const key = host.logoPath.startsWith('http') ? host.logoPath.split('.com/')[1] : host.logoPath; @@ -188,7 +188,7 @@ export class HostService { host.logoPath = await getPresignedUrl(bucket, key); } - if (host.accountManager.profileImage) { + if (host.accountManager?.profileImage) { const key = host.accountManager.profileImage.startsWith('http') ? host.accountManager.profileImage.split('.com/')[1] : host.accountManager.profileImage; From 39f182b8e93399717959467c38f299db25d88e8f Mon Sep 17 00:00:00 2001 From: Mayank Mishra Date: Tue, 2 Dec 2025 18:59:06 +0530 Subject: [PATCH 3/4] sending city state abd country in getbyidAM --- .../minglaradmin/services/minglar.service.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/modules/minglaradmin/services/minglar.service.ts b/src/modules/minglaradmin/services/minglar.service.ts index f4f25cd..6834998 100644 --- a/src/modules/minglaradmin/services/minglar.service.ts +++ b/src/modules/minglaradmin/services/minglar.service.ts @@ -1583,6 +1583,24 @@ export class MinglarService { locationLat: true, locationLong: true, locationName: true, + country: { + select: { + id: true, + countryName: true + } + }, + cities: { + select: { + id: true, + cityName: true, + } + }, + states: { + select: { + id: true, + stateName: true + } + } } }, userDocuments: { From 4f8274adb999aa31e367e3ebad2a7028e342d8a6 Mon Sep 17 00:00:00 2001 From: Mayank Mishra Date: Tue, 2 Dec 2025 19:00:30 +0530 Subject: [PATCH 4/4] Add pinCode field to location selection in MinglarService --- src/modules/minglaradmin/services/minglar.service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/minglaradmin/services/minglar.service.ts b/src/modules/minglaradmin/services/minglar.service.ts index 6834998..9c1c0be 100644 --- a/src/modules/minglaradmin/services/minglar.service.ts +++ b/src/modules/minglaradmin/services/minglar.service.ts @@ -1583,6 +1583,7 @@ export class MinglarService { locationLat: true, locationLong: true, locationName: true, + pinCode: true, country: { select: { id: true,