fixed the check availability api and sending the interested and bucket count in the connection api
This commit is contained in:
@@ -362,6 +362,9 @@ export class SchedulingService {
|
||||
isActive: true,
|
||||
startDate: { lte: date },
|
||||
OR: [{ endDate: null }, { endDate: { gte: date } }],
|
||||
ScheduleDetails: {
|
||||
some: {}
|
||||
}
|
||||
},
|
||||
include: {
|
||||
activityVenue: {
|
||||
|
||||
@@ -50,64 +50,73 @@ export const handler = safeHandler(async (
|
||||
const activity = activityDetails.activity;
|
||||
|
||||
// Rooms: combine ActivityVenues with their respective slots for the selected date
|
||||
const Venues = (activity.ActivityVenues || []).map((v: any) => {
|
||||
const header = scheduleDetails.find((h: any) => h.activityVenue?.venueXid === v.id);
|
||||
const Venues = (activity.ActivityVenues || [])
|
||||
.map((v: any) => {
|
||||
const header = scheduleDetails.find(
|
||||
(h: any) => h.activityVenue?.venueXid === v.id
|
||||
);
|
||||
|
||||
const roomSlots = (header?.slots || []).map((s: any) => {
|
||||
let status = 'Available';
|
||||
if (s.maxCapacity === 0) status = 'Housefull';
|
||||
else if (s.maxCapacity <= 2) status = '2 Slots Left';
|
||||
else if (s.maxCapacity <= 5) status = 'Fast Filling';
|
||||
if (!header || !header.slots?.length) {
|
||||
return null; // ❌ venue has no slots for selected date
|
||||
}
|
||||
|
||||
const roomSlots = header.slots.map((s: any) => {
|
||||
let status = "Available";
|
||||
|
||||
if (s.maxCapacity === 0) status = "Housefull";
|
||||
else if (s.maxCapacity <= 2) status = "2 Slots Left";
|
||||
else if (s.maxCapacity <= 5) status = "Fast Filling";
|
||||
|
||||
return {
|
||||
slotId: s.slotId,
|
||||
startTime: s.startTime,
|
||||
endTime: s.endTime,
|
||||
status,
|
||||
maxCapacity: s.maxCapacity,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
slotId: s.slotId,
|
||||
startTime: s.startTime,
|
||||
endTime: s.endTime,
|
||||
status,
|
||||
maxCapacity: s.maxCapacity,
|
||||
venueXid: v.id,
|
||||
venueName: v.venueName,
|
||||
venueLabel: v.venueLabel,
|
||||
venueCapacity: v.venueCapacity,
|
||||
availableSeats: v.availableSeats ?? null,
|
||||
price: v.ActivityPrices?.[0]?.sellPrice ?? null,
|
||||
endDate: header?.endDate ?? null,
|
||||
slots: roomSlots,
|
||||
slotsCount: roomSlots.length,
|
||||
venueMedia: (v.ActivityVenueArtifacts || []).map((media: any) => ({
|
||||
id: media.id,
|
||||
mediaType: media.mediaType,
|
||||
mediaFileName: media.mediaFileName,
|
||||
presignedUrl: media.presignedUrl,
|
||||
})),
|
||||
};
|
||||
});
|
||||
})
|
||||
.filter(Boolean); // ✅ removes null venues
|
||||
|
||||
return {
|
||||
venueXid: v.id,
|
||||
venueName: v.venueName,
|
||||
venueLabel: v.venueLabel,
|
||||
venueCapacity: v.venueCapacity,
|
||||
availableSeats: v.availableSeats ?? null,
|
||||
price: v.ActivityPrices?.[0]?.sellPrice ?? null,
|
||||
endDate: header?.endDate ?? null,
|
||||
slots: roomSlots,
|
||||
slotsCount: roomSlots.length,
|
||||
venueMedia: (v.ActivityVenueArtifacts || []).map((media: any) => ({
|
||||
id: media.id,
|
||||
mediaType: media.mediaType,
|
||||
mediaFileName: media.mediaFileName, // original S3 key / URL
|
||||
presignedUrl: media.presignedUrl, // presigned URL
|
||||
})),
|
||||
// derive check-in/out from all room slots (earliest start, latest end)
|
||||
const allSlots = Venues.flatMap(r => r.slots || []);
|
||||
const startTimes = allSlots.map(s => s.startTime).filter(Boolean);
|
||||
const endTimes = allSlots.map(s => s.endTime).filter(Boolean);
|
||||
const checkInTime = startTimes.length ? startTimes.sort()[0] : null;
|
||||
const checkOutTime = endTimes.length ? endTimes.sort().reverse()[0] : null;
|
||||
|
||||
const responsePayload = {
|
||||
selectedDate,
|
||||
Venues,
|
||||
checkInTime,
|
||||
checkOutTime,
|
||||
};
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
},
|
||||
body: JSON.stringify({ success: true, data: responsePayload }),
|
||||
};
|
||||
});
|
||||
|
||||
// derive check-in/out from all room slots (earliest start, latest end)
|
||||
const allSlots = Venues.flatMap(r => r.slots || []);
|
||||
const startTimes = allSlots.map(s => s.startTime).filter(Boolean);
|
||||
const endTimes = allSlots.map(s => s.endTime).filter(Boolean);
|
||||
const checkInTime = startTimes.length ? startTimes.sort()[0] : null;
|
||||
const checkOutTime = endTimes.length ? endTimes.sort().reverse()[0] : null;
|
||||
|
||||
const responsePayload = {
|
||||
selectedDate,
|
||||
Venues,
|
||||
checkInTime,
|
||||
checkOutTime,
|
||||
};
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
},
|
||||
body: JSON.stringify({ success: true, data: responsePayload }),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -2023,21 +2023,25 @@ export class UserService {
|
||||
},
|
||||
});
|
||||
|
||||
// const userLocation = await tx.userAddressDetails.findFirst({
|
||||
// where: { userXid: userId },
|
||||
// select: {
|
||||
// locationLat: true,
|
||||
// locationLong: true,
|
||||
// },
|
||||
// });
|
||||
if (!activity) {
|
||||
throw new Error("Activity not found");
|
||||
}
|
||||
|
||||
// const userLat = userLocation?.locationLat ?? null;
|
||||
// const userLng = userLocation?.locationLong ?? null;
|
||||
const userLocation = await tx.userAddressDetails.findFirst({
|
||||
where: { userXid: userId },
|
||||
select: {
|
||||
locationLat: true,
|
||||
locationLong: true,
|
||||
},
|
||||
});
|
||||
|
||||
// console.log(userLat, "UserLat")
|
||||
// console.log(userLng, "UserLong")
|
||||
// console.log(activity.checkInLat, "activityCheckIn")
|
||||
// console.log(activity.checkInLong, "activityCheckLong")
|
||||
const userLat = userLocation?.locationLat ?? null;
|
||||
const userLng = userLocation?.locationLong ?? null;
|
||||
|
||||
console.log(userLat, "UserLat")
|
||||
console.log(userLng, "UserLong")
|
||||
console.log(activity.checkInLat, "activityCheckIn")
|
||||
console.log(activity.checkInLong, "activityCheckLong")
|
||||
|
||||
// let distance = 0;
|
||||
|
||||
@@ -2052,8 +2056,10 @@ export class UserService {
|
||||
// userLng,
|
||||
// activity.checkInLat,
|
||||
// activity.checkInLong
|
||||
// );
|
||||
// }
|
||||
// )
|
||||
// };
|
||||
|
||||
// console.log(distance, "Distance is this")
|
||||
|
||||
// ================= PRESIGNED URL SECTION =================
|
||||
|
||||
@@ -2165,9 +2171,10 @@ export class UserService {
|
||||
})
|
||||
: 0;
|
||||
|
||||
const prices = activity.ActivityVenues.flatMap((v) =>
|
||||
v.ActivityPrices.map((p) => p.sellPrice),
|
||||
).filter((p) => p !== null) as number[];
|
||||
const prices =
|
||||
activity?.ActivityVenues?.flatMap((v) =>
|
||||
v.ActivityPrices.map((p) => p.sellPrice)
|
||||
).filter((p) => p !== null) ?? [];
|
||||
|
||||
const cheapestPrice = prices.length > 0 ? Math.min(...prices) : null;
|
||||
|
||||
@@ -2909,6 +2916,25 @@ export class UserService {
|
||||
])
|
||||
);
|
||||
|
||||
const userBucketInterested = await tx.userBucketInterested.findMany({
|
||||
where: {
|
||||
userXid: userId,
|
||||
isActive: true,
|
||||
},
|
||||
select: {
|
||||
activityXid: true,
|
||||
isBucket: true,
|
||||
},
|
||||
});
|
||||
|
||||
const userBucketActivityIds = userBucketInterested
|
||||
.filter(u => u.isBucket)
|
||||
.map(u => u.activityXid);
|
||||
|
||||
const userInterestedActivityIds = userBucketInterested
|
||||
.filter(u => !u.isBucket)
|
||||
.map(u => u.activityXid);
|
||||
|
||||
/* =====================================================
|
||||
1️⃣ FETCH ALL CANDIDATES FOR INTERESTS (SIMPLE SORT)
|
||||
===================================================== */
|
||||
@@ -3241,6 +3267,8 @@ export class UserService {
|
||||
citiesDiscovered: 10,
|
||||
loggedInNetworkCount: 0,
|
||||
citiesInNetworkCount: 0,
|
||||
interestedCount: userInterestedActivityIds.length,
|
||||
bucketCount: userBucketActivityIds.length,
|
||||
pagination: {
|
||||
page,
|
||||
limit,
|
||||
|
||||
Reference in New Issue
Block a user