cal.pub0.org/lib/utils/webhookSubscriptions.ts

43 lines
930 B
TypeScript
Raw Normal View History

2022-06-10 06:10:38 +00:00
import { WebhookTriggerEvents } from "@prisma/client";
import prisma from "@calcom/prisma";
export type GetSubscriberOptions = {
userId: number;
eventTypeId: number;
triggerEvent: WebhookTriggerEvents;
};
/** @note will this not work with custom prisma? since we're importing prisma directly and not passing it from request here **/
2022-06-10 06:10:38 +00:00
const getWebhooks = async (options: GetSubscriberOptions) => {
const { userId, eventTypeId } = options;
const allWebhooks = await prisma.webhook.findMany({
where: {
OR: [
{
userId,
},
{
eventTypeId,
},
],
AND: {
eventTriggers: {
has: options.triggerEvent,
},
active: {
equals: true,
},
},
},
select: {
subscriberUrl: true,
payloadTemplate: true,
appId: true,
},
});
return allWebhooks;
};
export default getWebhooks;