Skip to content

Commit fa11e10

Browse files
feat: remove 3-attendee limitation from CSV export (calcom#22092)
Co-authored-by: eunjae@cal.com <hey@eunjae.dev> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent a8f5bd6 commit fa11e10

1 file changed

Lines changed: 38 additions & 16 deletions

File tree

packages/features/insights/server/events.ts

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -484,16 +484,34 @@ class EventsInsights {
484484
: booking.attendees;
485485

486486
const formattedAttendees = attendeeList
487-
.slice(0, 3)
488-
.map((attendee) => (attendee ? `${attendee.name} (${attendee.email})` : null));
487+
.map((attendee) => (attendee ? `${attendee.name} (${attendee.email})` : null))
488+
.filter(Boolean);
489489

490490
return [
491491
booking.uid,
492+
{ attendeeList: formattedAttendees, noShowGuest: attendeeList[0]?.noShow || false },
493+
];
494+
})
495+
);
496+
497+
const maxAttendees = Math.max(
498+
...Array.from(bookingMap.values()).map((data) => data.attendeeList.length),
499+
0
500+
);
501+
502+
const finalBookingMap = new Map(
503+
Array.from(bookingMap.entries()).map(([uid, data]) => {
504+
const attendeeFields: Record<string, string | null> = {};
505+
506+
for (let i = 1; i <= maxAttendees; i++) {
507+
attendeeFields[`attendee${i}`] = data.attendeeList[i - 1] || null;
508+
}
509+
510+
return [
511+
uid,
492512
{
493-
noShowGuest: attendeeList[0]?.noShow || false,
494-
attendee1: formattedAttendees[0] || null,
495-
attendee2: formattedAttendees[1] || null,
496-
attendee3: formattedAttendees[2] || null,
513+
noShowGuest: data.noShowGuest,
514+
...attendeeFields,
497515
},
498516
];
499517
})
@@ -502,33 +520,37 @@ class EventsInsights {
502520
const data = csvData.map((bookingTimeStatus) => {
503521
if (!bookingTimeStatus.uid) {
504522
// should not be reached because we filtered above
523+
const nullAttendeeFields: Record<string, null> = {};
524+
for (let i = 1; i <= maxAttendees; i++) {
525+
nullAttendeeFields[`attendee${i}`] = null;
526+
}
527+
505528
return {
506529
...bookingTimeStatus,
507530
noShowGuest: false,
508-
attendee1: null,
509-
attendee2: null,
510-
attendee3: null,
531+
...nullAttendeeFields,
511532
};
512533
}
513534

514-
const attendeeData = bookingMap.get(bookingTimeStatus.uid);
535+
const attendeeData = finalBookingMap.get(bookingTimeStatus.uid);
515536

516537
if (!attendeeData) {
538+
const nullAttendeeFields: Record<string, null> = {};
539+
for (let i = 1; i <= maxAttendees; i++) {
540+
nullAttendeeFields[`attendee${i}`] = null;
541+
}
542+
517543
return {
518544
...bookingTimeStatus,
519545
noShowGuest: false,
520-
attendee1: null,
521-
attendee2: null,
522-
attendee3: null,
546+
...nullAttendeeFields,
523547
};
524548
}
525549

526550
return {
527551
...bookingTimeStatus,
528552
noShowGuest: attendeeData.noShowGuest,
529-
attendee1: attendeeData.attendee1,
530-
attendee2: attendeeData.attendee2,
531-
attendee3: attendeeData.attendee3,
553+
...Object.fromEntries(Object.entries(attendeeData).filter(([key]) => key.startsWith("attendee"))),
532554
};
533555
});
534556

0 commit comments

Comments
 (0)