From 13863edbcb56df796afbbff20aeed919621f81f5 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:18:46 +0000 Subject: [PATCH] feat(insights): Include all guests in CSV export Co-Authored-By: Bailey Pumfleet --- packages/features/insights/server/events.ts | 24 +++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/features/insights/server/events.ts b/packages/features/insights/server/events.ts index 434f4ecd6268c4..d2e1fe1e523d49 100644 --- a/packages/features/insights/server/events.ts +++ b/packages/features/insights/server/events.ts @@ -428,26 +428,28 @@ class EventsInsights { }, }); - const bookingMap = new Map(bookings.map((booking) => [booking.uid, booking.attendees[0] || null])); + const bookingMap = new Map(bookings.map((booking) => [booking.uid, booking.attendees])); - return csvData.map((bookingTimeStatus) => { + return csvData.flatMap((bookingTimeStatus) => { if (!bookingTimeStatus.uid) { // should not be reached because we filtered above - return bookingTimeStatus; + return [bookingTimeStatus]; } - const booker = bookingMap.get(bookingTimeStatus.uid); + const attendees = bookingMap.get(bookingTimeStatus.uid); - if (!booker) { - return bookingTimeStatus; + if (!attendees?.length) { + return [bookingTimeStatus]; } - return { + // Return a row for each attendee + return attendees.map((attendee, index) => ({ ...bookingTimeStatus, - noShowGuest: booker.noShow, - bookerEmail: booker.email, - bookerName: booker.name, - }; + noShowGuest: attendee.noShow, + guestEmail: attendee.email, + guestName: attendee.name, + isBooker: index === 0 ? "yes" : "no", // Mark the first attendee as the booker + })); }); };