fixes
All checks were successful
Build And Push Image / docker (push) Successful in 4m16s

This commit is contained in:
2025-08-13 15:57:34 +02:00
parent db19eb2708
commit 5371ad4fa2
4 changed files with 321 additions and 74 deletions

View File

@@ -253,6 +253,23 @@ export function createNocoDBEventsClient() {
// Apply field normalization like members system
if (result.list) {
result.list = result.list.map(normalizeEventFieldsFromNocoDB);
// Update attendee counts for all events
result.list = await Promise.all(
result.list.map(async (event) => {
try {
const eventId = event.event_id || event.id || (event as any).Id;
const updatedCount = await this.calculateEventAttendeeCount(eventId.toString());
return {
...event,
current_attendees: updatedCount.toString()
};
} catch (error) {
console.log('[nocodb-events] ⚠️ Failed to calculate attendee count for event:', event.title, error);
return event; // Return original if calculation fails
}
})
);
}
return result;
@@ -490,6 +507,7 @@ export function createNocoDBEventsClient() {
payment_reference: rsvpData.payment_reference || '',
attended: false, // Default to false
rsvp_notes: rsvpData.rsvp_notes || '',
extra_guests: rsvpData.extra_guests || '0', // Include guest count
is_member_pricing: rsvpData.is_member_pricing === 'true' || rsvpData.is_member_pricing === true
};
@@ -651,6 +669,74 @@ export function createNocoDBEventsClient() {
console.error('[nocodb-events] ❌ Error updating RSVP:', error);
throw error;
}
},
/**
* Get all RSVPs for an event with optional status filter
*/
async getEventRSVPs(eventId: string, rsvpStatus?: string) {
console.log('[nocodb-events] Getting RSVPs for event:', eventId, 'with status:', rsvpStatus);
try {
try {
// Build where clause
let whereClause = `(event_id,eq,${eventId})`;
if (rsvpStatus) {
whereClause += `~and(rsvp_status,eq,${rsvpStatus})`;
}
// Try to get from RSVP table first
const rsvps = await $fetch<{list: any[]}>(createEventTableUrl(EventTable.EventRSVPs), {
headers: {
"xc-token": getNocoDbConfiguration().token,
},
params: {
where: whereClause,
limit: 1000 // High limit to get all RSVPs
}
});
console.log('[nocodb-events] ✅ Found', rsvps.list?.length || 0, 'RSVPs for event:', eventId);
return rsvps.list || [];
} catch (rsvpTableError: any) {
console.log('[nocodb-events] ⚠️ RSVP table not available, returning empty array');
// Return empty array if table not available
return [];
}
} catch (error: any) {
console.error('[nocodb-events] ❌ Error getting event RSVPs:', error);
return []; // Return empty array instead of throwing to prevent blocking
}
},
/**
* Calculate total attendee count for an event (confirmed RSVPs + their guests)
*/
async calculateEventAttendeeCount(eventId: string): Promise<number> {
console.log('[nocodb-events] Calculating attendee count for event:', eventId);
try {
// Get all confirmed RSVPs for this event
const confirmedRSVPs = await this.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('[nocodb-events] ✅ Calculated total attendees:', totalAttendees, 'from', confirmedRSVPs.length, 'confirmed RSVPs');
return totalAttendees;
} catch (error) {
console.error('[nocodb-events] ❌ Error calculating attendee count for event:', eventId, error);
return 0; // Return 0 if calculation fails
}
}
};