cal/packages/lib/getTeamIdFromEventType.ts
Pradumn Kumar 6b9d2331fc
fix: Managed Event Type Webhooks (#10300)
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
2023-07-25 13:05:02 -04:00

30 lines
611 B
TypeScript

import prisma from "@calcom/prisma";
export async function getTeamIdFromEventType({
eventType,
}: {
eventType: { team: { id: number | null } | null; parentId: number | null };
}) {
if (!eventType) {
return null;
}
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;
}
}