From 40218016988237d4257070ce2e4844307c2152be Mon Sep 17 00:00:00 2001 From: Benny Joo Date: Wed, 23 Oct 2024 18:55:11 -0400 Subject: [PATCH] feat: attach booker name/email to insights CSV (#17280) --- packages/features/insights/server/events.ts | 34 ++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/features/insights/server/events.ts b/packages/features/insights/server/events.ts index bdd0e2044c..38d3bc78a3 100644 --- a/packages/features/insights/server/events.ts +++ b/packages/features/insights/server/events.ts @@ -207,7 +207,39 @@ class EventsInsights { where: whereConditional, }); - return csvData; + const csvDataWithBookerInfo = await Promise.all( + csvData.map(async (bookingTimeStatus) => { + if (!bookingTimeStatus.uid) { + return bookingTimeStatus; + } + + const booking = await prisma.booking.findUnique({ + where: { uid: bookingTimeStatus.uid }, + select: { + attendees: { + select: { + name: true, + email: true, + }, + }, + }, + }); + + if (!booking || !booking.attendees.length) { + return bookingTimeStatus; + } + const { attendees } = booking; + const booker = attendees[0]; + + return { + ...bookingTimeStatus, + bookerEmail: booker.email, + bookerName: booker.name, + }; + }) + ); + + return csvDataWithBookerInfo; }; /*