fix: mark guest are no show (#17588)
* fix: mark guest are no show * chore: missing import * nit * fix: type err
This commit is contained in:
1 parent
84fb9bb371
commit
c7f11c6795
2 files changed
+47
-6
No files matched your search
@@ -111,6 +111,7 @@ export const prepareNoShowTrigger = async (
|
||||
booking: Booking;
|
||||
webhook: TWebhook;
|
||||
hostsThatDidntJoinTheCall: Host[];
|
||||
hostsThatJoinedTheCall: Host[];
|
||||
numberOfHostsThatJoined: number;
|
||||
didGuestJoinTheCall: boolean;
|
||||
} | void> => {
|
||||
@@ -148,9 +149,16 @@ export const prepareNoShowTrigger = async (
|
||||
const hosts = getHosts(booking);
|
||||
const allParticipants = meetingDetails.data.flatMap((meeting) => meeting.participants);
|
||||
|
||||
const hostsThatDidntJoinTheCall = hosts.filter(
|
||||
(host) => !checkIfUserJoinedTheCall(host.id, allParticipants)
|
||||
);
|
||||
const hostsThatJoinedTheCall: Host[] = [];
|
||||
const hostsThatDidntJoinTheCall: Host[] = [];
|
||||
|
||||
for (const host of hosts) {
|
||||
if (checkIfUserJoinedTheCall(host.id, allParticipants)) {
|
||||
hostsThatJoinedTheCall.push(host);
|
||||
} else {
|
||||
hostsThatDidntJoinTheCall.push(host);
|
||||
}
|
||||
}
|
||||
|
||||
const numberOfHostsThatJoined = hosts.length - hostsThatDidntJoinTheCall.length;
|
||||
|
||||
@@ -158,5 +166,12 @@ export const prepareNoShowTrigger = async (
|
||||
(meeting) => meeting.max_participants < numberOfHostsThatJoined
|
||||
);
|
||||
|
||||
return { hostsThatDidntJoinTheCall, booking, numberOfHostsThatJoined, webhook, didGuestJoinTheCall };
|
||||
return {
|
||||
hostsThatDidntJoinTheCall,
|
||||
hostsThatJoinedTheCall,
|
||||
booking,
|
||||
numberOfHostsThatJoined,
|
||||
webhook,
|
||||
didGuestJoinTheCall,
|
||||
};
|
||||
};
|
||||
@@ -1,12 +1,36 @@
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { WebhookTriggerEvents } from "@calcom/prisma/enums";
|
||||
|
||||
import { calculateMaxStartTime, sendWebhookPayload, prepareNoShowTrigger } from "./common";
|
||||
import { calculateMaxStartTime, sendWebhookPayload, prepareNoShowTrigger, log } from "./common";
|
||||
import type { Host } from "./common";
|
||||
|
||||
const markAllGuestNoshowInBooking = async ({
|
||||
bookingId,
|
||||
hostsThatJoinedTheCall,
|
||||
}: {
|
||||
bookingId: number;
|
||||
hostsThatJoinedTheCall: Host[];
|
||||
}) => {
|
||||
try {
|
||||
const hostsThatJoinedTheCallEmails = hostsThatJoinedTheCall.map((h) => h.email);
|
||||
|
||||
await prisma.attendee.updateMany({
|
||||
where: {
|
||||
bookingId,
|
||||
email: { notIn: hostsThatJoinedTheCallEmails },
|
||||
},
|
||||
data: { noShow: true },
|
||||
});
|
||||
} catch (err) {
|
||||
log.error("Error marking guests as no show in booking", err);
|
||||
}
|
||||
};
|
||||
|
||||
export async function triggerGuestNoShow(payload: string): Promise<void> {
|
||||
const result = await prepareNoShowTrigger(payload);
|
||||
if (!result) return;
|
||||
|
||||
const { webhook, booking, didGuestJoinTheCall } = result;
|
||||
const { webhook, booking, hostsThatJoinedTheCall, didGuestJoinTheCall } = result;
|
||||
|
||||
const maxStartTime = calculateMaxStartTime(booking.startTime, webhook.time, webhook.timeUnit);
|
||||
|
||||
@@ -17,5 +41,7 @@ export async function triggerGuestNoShow(payload: string): Promise<void> {
|
||||
booking,
|
||||
maxStartTime
|
||||
);
|
||||
|
||||
await markAllGuestNoshowInBooking({ bookingId: booking.id, hostsThatJoinedTheCall });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user