From 9e3d369ac3400c76b7aa80d0e96c1e47cd14f7b2 Mon Sep 17 00:00:00 2001 From: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Date: Tue, 3 Dec 2024 15:06:59 +0530 Subject: [PATCH] feat: return participants (#17950) * feat: return participants * fix: update tests --- .../tasker/tasks/triggerNoShow/common.ts | 29 +++++++++++++ .../tasks/triggerNoShow/triggerGuestNoShow.ts | 11 ++++- .../triggerNoShow/triggerHostNoShow.test.ts | 43 +++++++++++-------- .../tasks/triggerNoShow/triggerHostNoShow.ts | 3 +- 4 files changed, 65 insertions(+), 21 deletions(-) diff --git a/packages/features/tasker/tasks/triggerNoShow/common.ts b/packages/features/tasker/tasks/triggerNoShow/common.ts index 8fab17c7d3..a7aebd0648 100644 --- a/packages/features/tasker/tasks/triggerNoShow/common.ts +++ b/packages/features/tasker/tasks/triggerNoShow/common.ts @@ -58,6 +58,7 @@ export function sendWebhookPayload( triggerEvent: WebhookTriggerEvents, booking: Booking, maxStartTime: number, + participants: ParticipantsWithEmail, originalRescheduledBooking?: OriginalRescheduledBooking, hostEmail?: string ): Promise { @@ -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 { + 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, }; }; diff --git a/packages/features/tasker/tasks/triggerNoShow/triggerGuestNoShow.ts b/packages/features/tasker/tasks/triggerNoShow/triggerGuestNoShow.ts index ff8aa3a2cc..d7c27f34ce 100644 --- a/packages/features/tasker/tasks/triggerNoShow/triggerGuestNoShow.ts +++ b/packages/features/tasker/tasks/triggerNoShow/triggerGuestNoShow.ts @@ -30,8 +30,14 @@ export async function triggerGuestNoShow(payload: string): Promise { 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 { WebhookTriggerEvents.AFTER_GUESTS_CAL_VIDEO_NO_SHOW, booking, maxStartTime, + participants, originalRescheduledBooking ); diff --git a/packages/features/tasker/tasks/triggerNoShow/triggerHostNoShow.test.ts b/packages/features/tasker/tasks/triggerNoShow/triggerHostNoShow.test.ts index 9e17c17c14..3e35c2e63c 100644 --- a/packages/features/tasker/tasks/triggerNoShow/triggerHostNoShow.test.ts +++ b/packages/features/tasker/tasks/triggerNoShow/triggerHostNoShow.test.ts @@ -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`, diff --git a/packages/features/tasker/tasks/triggerNoShow/triggerHostNoShow.ts b/packages/features/tasker/tasks/triggerNoShow/triggerHostNoShow.ts index 156cab9027..c7ec3040b6 100644 --- a/packages/features/tasker/tasks/triggerNoShow/triggerHostNoShow.ts +++ b/packages/features/tasker/tasks/triggerNoShow/triggerHostNoShow.ts @@ -37,7 +37,7 @@ export async function triggerHostNoShow(payload: string): Promise { 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 { WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW, booking, maxStartTime, + participants, originalRescheduledBooking, host.email );