feat: return participants (#17950)

* feat: return participants

* fix: update tests
This commit is contained in:
Udit Takkar authored and GitHub committed 2024-12-03 09:36:59 +00:00
1 parent 356c603e3f
commit 9e3d369ac3
4 files changed
+65 -21

No files matched your search

@@ -58,6 +58,7 @@ export function sendWebhookPayload(
triggerEvent: WebhookTriggerEvents,
booking: Booking,
maxStartTime: number,
participants: ParticipantsWithEmail,
originalRescheduledBooking?: OriginalRescheduledBooking,
hostEmail?: string
): Promise<any> {
@@ -75,6 +76,7 @@ export function sendWebhookPayload(
startTime: booking.startTime,
attendees: booking.attendees,
endTime: booking.endTime,
participants,
...(!!hostEmail ? { hostEmail } : {}),
...(originalRescheduledBooking ? { rescheduledBy: originalRescheduledBooking.rescheduledBy } : {}),
eventType: {
@@ -113,6 +115,29 @@ export function checkIfUserJoinedTheCall(userId: number, allParticipants: Partic
);
}
const getUserById = async (userId: number) => {
return prisma.user.findUnique({
where: { id: userId },
});
};
type ParticipantsWithEmail = (Participants[number] & { email?: string })[];
export async function getParticipantsWithEmail(
allParticipants: Participants
): Promise<ParticipantsWithEmail> {
const participantsWithEmail = await Promise.all(
allParticipants.map(async (participant) => {
if (!participant.user_id) return participant;
const user = await getUserById(parseInt(participant.user_id));
return { ...participant, email: user?.email };
})
);
return participantsWithEmail;
}
export const log = logger.getSubLogger({ prefix: ["triggerNoShowTask"] });
export const prepareNoShowTrigger = async (
@@ -125,6 +150,7 @@ export const prepareNoShowTrigger = async (
numberOfHostsThatJoined: number;
didGuestJoinTheCall: boolean;
originalRescheduledBooking?: OriginalRescheduledBooking;
participants: ParticipantsWithEmail;
} | void> => {
const { bookingId, webhook } = ZSendNoShowWebhookPayloadSchema.parse(JSON.parse(payload));
@@ -192,6 +218,8 @@ export const prepareNoShowTrigger = async (
(meeting) => meeting.max_participants < numberOfHostsThatJoined
);
const participantsWithEmail = await getParticipantsWithEmail(allParticipants);
return {
hostsThatDidntJoinTheCall,
hostsThatJoinedTheCall,
@@ -200,5 +228,6 @@ export const prepareNoShowTrigger = async (
webhook,
didGuestJoinTheCall,
originalRescheduledBooking,
participants: participantsWithEmail,
};
};
@@ -30,8 +30,14 @@ export async function triggerGuestNoShow(payload: string): Promise<void> {
const result = await prepareNoShowTrigger(payload);
if (!result) return;
const { webhook, booking, hostsThatJoinedTheCall, didGuestJoinTheCall, originalRescheduledBooking } =
result;
const {
webhook,
booking,
hostsThatJoinedTheCall,
didGuestJoinTheCall,
originalRescheduledBooking,
participants,
} = result;
const maxStartTime = calculateMaxStartTime(booking.startTime, webhook.time, webhook.timeUnit);
@@ -41,6 +47,7 @@ export async function triggerGuestNoShow(payload: string): Promise<void> {
WebhookTriggerEvents.AFTER_GUESTS_CAL_VIDEO_NO_SHOW,
booking,
maxStartTime,
participants,
originalRescheduledBooking
);
@@ -159,6 +159,7 @@ describe("Trigger Host No Show:", () => {
attendees: [],
bookingId: 222,
bookingUid: uidOfBooking,
participants: [],
hostEmail: "organizer@example.com",
startTime: `${plus1DateString}T05:00:00.000Z`,
endTime: `${plus1DateString}T05:15:00.000Z`,
@@ -264,6 +265,16 @@ describe("Trigger Host No Show:", () => {
})
);
const MOCKED_PARTICIPANTS = [
{
user_id: null,
participant_id: "MOCK_PARTICIPANT_ID",
user_name: "MOCK_USER_NAME",
join_time: 0,
duration: 15,
},
];
const MOCKED_MEETING_SESSIONS = {
total_count: 1,
data: [
@@ -274,15 +285,7 @@ describe("Trigger Host No Show:", () => {
duration: 15,
max_participants: 1,
// User with id 101 is not in the participants list
participants: [
{
user_id: null,
participant_id: "MOCK_PARTICIPANT_ID",
user_name: "MOCK_USER_NAME",
join_time: 0,
duration: 15,
},
],
participants: MOCKED_PARTICIPANTS,
},
],
};
@@ -320,6 +323,7 @@ describe("Trigger Host No Show:", () => {
attendees: [],
bookingId: 222,
bookingUid: uidOfBooking,
participants: MOCKED_PARTICIPANTS,
hostEmail: "organizer@example.com",
startTime: `${plus1DateString}T05:00:00.000Z`,
endTime: `${plus1DateString}T05:15:00.000Z`,
@@ -464,6 +468,16 @@ describe("Trigger Host No Show:", () => {
})
);
const MOCKED_PARTICIPANTS = [
{
user_id: null,
participant_id: "MOCK_PARTICIPANT_ID",
user_name: "MOCK_USER_NAME",
join_time: 0,
duration: 15,
},
];
const MOCKED_MEETING_SESSIONS = {
total_count: 1,
data: [
@@ -474,15 +488,7 @@ describe("Trigger Host No Show:", () => {
duration: 15,
max_participants: 1,
// User with id 101 is not in the participants list
participants: [
{
user_id: null,
participant_id: "MOCK_PARTICIPANT_ID",
user_name: "MOCK_USER_NAME",
join_time: 0,
duration: 15,
},
],
participants: MOCKED_PARTICIPANTS,
},
],
};
@@ -520,6 +526,7 @@ describe("Trigger Host No Show:", () => {
attendees: [],
bookingId: 224,
bookingUid: newUidOfBooking,
participants: MOCKED_PARTICIPANTS,
hostEmail: "organizer@example.com",
startTime: `${plus1DateString}T05:15:00.000Z`,
endTime: `${plus1DateString}T05:30:00.000Z`,
@@ -37,7 +37,7 @@ export async function triggerHostNoShow(payload: string): Promise<void> {
const result = await prepareNoShowTrigger(payload);
if (!result) return;
const { booking, webhook, hostsThatDidntJoinTheCall, originalRescheduledBooking } = result;
const { booking, webhook, hostsThatDidntJoinTheCall, originalRescheduledBooking, participants } = result;
const maxStartTime = calculateMaxStartTime(booking.startTime, webhook.time, webhook.timeUnit);
@@ -47,6 +47,7 @@ export async function triggerHostNoShow(payload: string): Promise<void> {
WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW,
booking,
maxStartTime,
participants,
originalRescheduledBooking,
host.email
);