9447f16b82
* WIP * WIP * Type and migration fixes * Adds missing default import * Fixes import * Fixes tRPC imports in App Store * Migrate stripe helpers * WIP * Type fixes * Type fix? * Test fixes * Adds missing stripe packages * Moved queries to lib instead Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
44 lines
823 B
TypeScript
44 lines
823 B
TypeScript
import { WebhookTriggerEvents } from "@prisma/client";
|
|
|
|
import prisma from "@calcom/prisma";
|
|
|
|
export type GetSubscriberOptions = {
|
|
userId: number;
|
|
eventTypeId: number;
|
|
triggerEvent: WebhookTriggerEvents;
|
|
};
|
|
|
|
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,
|
|
secret: true,
|
|
},
|
|
});
|
|
|
|
return allWebhooks;
|
|
};
|
|
|
|
export default getWebhooks;
|