This commit is contained in:
@@ -135,6 +135,15 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
const newRSVP = await eventsClient.createRSVP(rsvpData);
|
||||
|
||||
// Update event attendee count
|
||||
try {
|
||||
await updateEventAttendeeCount(eventId);
|
||||
console.log('[RSVP] ✅ Updated event attendee count for event:', eventId);
|
||||
} catch (countError) {
|
||||
console.log('[RSVP] ⚠️ Failed to update attendee count:', countError);
|
||||
// Don't fail the RSVP creation if count update fails
|
||||
}
|
||||
|
||||
// Include payment information in response for paid events
|
||||
let responseData: any = newRSVP;
|
||||
|
||||
@@ -191,3 +200,37 @@ async function getRegistrationConfig() {
|
||||
accountHolder: 'MonacoUSA Association'
|
||||
};
|
||||
}
|
||||
|
||||
async function updateEventAttendeeCount(eventId: string) {
|
||||
console.log('[updateEventAttendeeCount] Updating attendee count for event:', eventId);
|
||||
|
||||
try {
|
||||
const eventsClient = createNocoDBEventsClient();
|
||||
|
||||
// Get all confirmed RSVPs for this event
|
||||
const confirmedRSVPs = await eventsClient.getEventRSVPs(eventId, 'confirmed');
|
||||
|
||||
// Calculate total attendees (confirmed RSVPs + their guests)
|
||||
let totalAttendees = 0;
|
||||
|
||||
for (const rsvp of confirmedRSVPs) {
|
||||
totalAttendees += 1; // The member themselves
|
||||
const guestCount = parseInt(rsvp.extra_guests || '0');
|
||||
totalAttendees += guestCount; // Add their guests
|
||||
}
|
||||
|
||||
console.log('[updateEventAttendeeCount] Calculated total attendees:', totalAttendees, 'from', confirmedRSVPs.length, 'RSVPs');
|
||||
|
||||
// Update the event's current_attendees field
|
||||
await eventsClient.update(eventId, {
|
||||
current_attendees: totalAttendees.toString()
|
||||
});
|
||||
|
||||
console.log('[updateEventAttendeeCount] ✅ Successfully updated event attendee count to:', totalAttendees);
|
||||
|
||||
return totalAttendees;
|
||||
} catch (error) {
|
||||
console.error('[updateEventAttendeeCount] ❌ Error updating attendee count:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user