2021-10-07 15:14:47 +00:00
|
|
|
import { WebhookTriggerEvents } from "@prisma/client";
|
|
|
|
|
2022-07-28 19:58:26 +00:00
|
|
|
import prisma from "@calcom/prisma";
|
2021-10-07 15:14:47 +00:00
|
|
|
|
2022-03-02 16:24:57 +00:00
|
|
|
export type GetSubscriberOptions = {
|
|
|
|
userId: number;
|
|
|
|
eventTypeId: number;
|
|
|
|
triggerEvent: WebhookTriggerEvents;
|
|
|
|
};
|
|
|
|
|
2022-08-26 21:58:08 +00:00
|
|
|
/** @deprecated use `packages/lib/webhooks/subscriptions.tsx` */
|
2022-05-03 23:16:59 +00:00
|
|
|
const getWebhooks = async (options: GetSubscriberOptions) => {
|
2022-03-02 16:24:57 +00:00
|
|
|
const { userId, eventTypeId } = options;
|
2021-10-07 15:14:47 +00:00
|
|
|
const allWebhooks = await prisma.webhook.findMany({
|
|
|
|
where: {
|
2022-03-02 16:24:57 +00:00
|
|
|
OR: [
|
|
|
|
{
|
|
|
|
userId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
eventTypeId,
|
|
|
|
},
|
|
|
|
],
|
2021-10-07 15:14:47 +00:00
|
|
|
AND: {
|
|
|
|
eventTriggers: {
|
2022-03-02 16:24:57 +00:00
|
|
|
has: options.triggerEvent,
|
2021-10-07 15:14:47 +00:00
|
|
|
},
|
|
|
|
active: {
|
|
|
|
equals: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
select: {
|
2022-08-15 20:18:41 +00:00
|
|
|
id: true,
|
2021-10-07 15:14:47 +00:00
|
|
|
subscriberUrl: true,
|
2021-11-22 11:37:07 +00:00
|
|
|
payloadTemplate: true,
|
2022-05-03 23:16:59 +00:00
|
|
|
appId: true,
|
2022-06-16 16:21:48 +00:00
|
|
|
secret: true,
|
2021-10-07 15:14:47 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-11-22 11:37:07 +00:00
|
|
|
return allWebhooks;
|
2021-10-07 15:14:47 +00:00
|
|
|
};
|
|
|
|
|
2022-05-03 23:16:59 +00:00
|
|
|
export default getWebhooks;
|