
* --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>
41 lines
787 B
TypeScript
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;
|