calcom/apps/web/lib/webhooks/subscriptions.tsx
Syed Ali Shahbaz d338504856
Webhooks to support event type association (#1889)
* --init database and queries

* fixed type check

* added webhook api for event types

* added webhook list in team event

* delete, edit webhook in team event

* updated webhook subtext for event type

* added discord integration to event type webhook

* check fix

* consistency

* minor code improvement

* lint fix

* Adds missing zod schemas

* requested changes pt1 --WIP

* requested changes pt2 --WIP

Co-authored-by: zomars <zomars@me.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-03-02 08:30:13 -07:00

41 lines
787 B
TypeScript

import { WebhookTriggerEvents } from "@prisma/client";
import prisma from "@lib/prisma";
export type GetSubscriberOptions = {
userId: number;
eventTypeId: number;
triggerEvent: WebhookTriggerEvents;
};
const getSubscribers = 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,
},
});
return allWebhooks;
};
export default getSubscribers;