fix: fixes issue with webhook not being triggered for managed events (#10025)

pull/9928/head
Pradumn Kumar 2023-07-11 13:16:24 +05:30 committed by GitHub
parent fc049e12b3
commit d097c1fada
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -647,6 +647,26 @@ function getCustomInputsResponses(
return customInputsResponses;
}
async function getTeamId({ eventType }: { eventType: Awaited<ReturnType<typeof getEventTypesFromDB>> }) {
if (eventType?.team?.id) {
return eventType.team.id;
}
// If it's a managed event we need to find the teamId for it from the parent
if (eventType.parentId) {
const managedEvent = await prisma.eventType.findFirst({
where: {
id: eventType.parentId,
},
select: {
teamId: true,
},
});
return managedEvent?.teamId;
}
}
async function handler(
req: NextApiRequest & { userId?: number | undefined },
{
@ -2225,11 +2245,14 @@ async function handler(
status: "ACCEPTED",
smsReminderNumber: booking?.smsReminderNumber || undefined,
};
const teamId = await getTeamId({ eventType });
const subscriberOptions: GetSubscriberOptions = {
userId: organizerUser.id,
eventTypeId,
triggerEvent: WebhookTriggerEvents.BOOKING_CREATED,
teamId: eventType.team?.id,
teamId,
};
if (isConfirmedByDefault) {
@ -2243,7 +2266,7 @@ async function handler(
userId: organizerUser.id,
eventTypeId,
triggerEvent: WebhookTriggerEvents.MEETING_ENDED,
teamId: eventType.team?.id,
teamId,
};
try {

View File

@ -94,6 +94,7 @@ const commons = {
parentId: null,
owner: null,
workflows: [],
parentId: null,
users: [user],
hosts: [],
metadata: EventTypeMetaDataSchema.parse({}),