Sending the presgined url of amenities
This commit is contained in:
@@ -1869,6 +1869,19 @@ export class HostService {
|
||||
});
|
||||
}
|
||||
|
||||
/************* ✨ Windsurf Command ⭐ *************/
|
||||
/**
|
||||
* Get all details of an activity and its venue.
|
||||
*
|
||||
* @param {number} activityXid - The id of the activity to fetch.
|
||||
*
|
||||
* @returns {Promise<object>} - The activity details with its venue.
|
||||
*
|
||||
* @example
|
||||
* const activity = await getAllDetailsOfActivityAndVenue(1);
|
||||
* console.log(activity);
|
||||
*/
|
||||
/******* 88cdc2a8-b07f-4da8-972a-4e00f5399a65 *******/
|
||||
async getAllDetailsOfActivityAndVenue(activityXid: number) {
|
||||
const activity = await this.prisma.activities.findFirst({
|
||||
where: { id: activityXid, isActive: true },
|
||||
@@ -2164,6 +2177,7 @@ export class HostService {
|
||||
select: {
|
||||
id: true,
|
||||
amenitiesName: true,
|
||||
amenitiesIcon: true
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2218,6 +2232,22 @@ export class HostService {
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(activity.ActivityAmenities)) {
|
||||
for (const item of activity.ActivityAmenities) {
|
||||
|
||||
const filePath = item?.amenities?.amenitiesIcon;
|
||||
if (!filePath) continue;
|
||||
|
||||
// ✅ Robust S3 key extraction
|
||||
const key = filePath.startsWith('http')
|
||||
? new URL(filePath).pathname.replace(/^\/+/, '')
|
||||
: filePath;
|
||||
|
||||
(item.amenities as any).presignedUrl = await getPresignedUrl(bucket, key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (Array.isArray(activity.ActivityVenues)) {
|
||||
for (const venue of activity.ActivityVenues) {
|
||||
if (!Array.isArray(venue.ActivityVenueArtifacts)) continue;
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { getPresignedUrl } from '../../../common/middlewares/aws/getPreSignedUrl';
|
||||
import config from '../../../config/config';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
|
||||
const bucket = config.aws.bucketName;
|
||||
|
||||
@Injectable()
|
||||
export class PrePopulateService {
|
||||
constructor(private prisma: PrismaClient) { }
|
||||
@@ -176,6 +182,8 @@ export class PrePopulateService {
|
||||
}),
|
||||
this.prisma.amenities.findMany({
|
||||
where: { isActive: true },
|
||||
select: { id: true, amenitiesName: true, amenitiesIcon: true },
|
||||
orderBy: { amenitiesName: 'asc' }
|
||||
}),
|
||||
this.prisma.allowedEntryTypes.findMany({
|
||||
where: { isActive: true },
|
||||
@@ -187,6 +195,22 @@ export class PrePopulateService {
|
||||
}),
|
||||
]);
|
||||
|
||||
if (aminitiesDetails?.length) {
|
||||
for (const amenity of aminitiesDetails) {
|
||||
if (amenity.amenitiesIcon) {
|
||||
|
||||
const filePath = amenity.amenitiesIcon;
|
||||
|
||||
// Extract key if full URL stored
|
||||
const key = filePath.startsWith('http')
|
||||
? filePath.split('.com/')[1]
|
||||
: filePath;
|
||||
|
||||
(amenity as any).presignedUrl = await getPresignedUrl(bucket, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
foodType,
|
||||
cuisineDetails,
|
||||
|
||||
Reference in New Issue
Block a user