* add webhook version schema * version the code * update version from numeric to date val * migration * update schema and build factory * update string * move version picker * tooltip instead of infobadge * -- * fix type * -- * fix type * fix type * -- * fix messed up merge * improvements to payloadfactory * extract version off of DB and instead keep it in IWebhookRepository * fix webhookform * fix type safety and routing ambiguity * scalable with easier factory extensions and base definition * fix types * -- * -- * clean up prisma/client type imports * fix * type fix * type fix * cleanup * add tests and registry changes * unintended file inclusion * type-fix * select in repo * -- * explicit return type * -- * fix type * fixes * feedback 1 * feedback 2 * use enum instead of string * fixes
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import type { WebhookForReservationCheck } from "./dto/types";
|
|
|
|
interface Params {
|
|
subscriberUrl: string;
|
|
id?: string;
|
|
webhooks?: WebhookForReservationCheck[];
|
|
teamId?: number;
|
|
userId?: number;
|
|
eventTypeId?: number;
|
|
platform?: boolean;
|
|
}
|
|
|
|
export const subscriberUrlReserved = ({
|
|
subscriberUrl,
|
|
id,
|
|
webhooks,
|
|
teamId,
|
|
userId,
|
|
eventTypeId,
|
|
platform,
|
|
}: Params): boolean => {
|
|
if (!teamId && !userId && !eventTypeId && !platform) {
|
|
throw new Error("Either teamId, userId, eventTypeId or platform must be provided.");
|
|
}
|
|
|
|
const findMatchingWebhook = (condition: (webhook: WebhookForReservationCheck) => boolean) => {
|
|
return !!webhooks?.find(
|
|
(webhook) => webhook.subscriberUrl === subscriberUrl && (!id || webhook.id !== id) && condition(webhook)
|
|
);
|
|
};
|
|
|
|
if (teamId) {
|
|
return findMatchingWebhook((webhook) => webhook.teamId === teamId);
|
|
}
|
|
if (eventTypeId) {
|
|
return findMatchingWebhook((webhook) => webhook.eventTypeId === eventTypeId);
|
|
}
|
|
if (platform) {
|
|
return findMatchingWebhook((webhook) => webhook.platform === true);
|
|
}
|
|
return findMatchingWebhook((webhook) => webhook.userId === userId);
|
|
};
|