* zapier and webhook * instructions for zapier * Fix types * fix types * revert adding zap template * Update packages/app-store/zapier/README.md Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> * Update packages/app-store/zapier/README.md Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> * Update packages/app-store/zapier/README.md Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> * Update packages/features/webhooks/lib/scheduleTrigger.ts Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> * wip * Fixes from comments, no more sendPayloadNoBooking * fix subscriberOptions teamIds param type * types * Update packages/features/webhooks/lib/sendPayload.ts * Re add zapierPayload to don't break old zaps * instead of metadata use oooEntry inside webhookPayload * undo comment message * Types * reset changes on yarn.lock * review changes * fix types * fix types * tentative fix for types in webhook * type improvements * fix description + clean up * revert yarn.lock changes * allow custom template for ooo entry * type fixes * type fix * fix donwloadLinks in payload * simplify some types * allow array or number for teamId * same payload for test trigger * code clean up * fix no show e2e test * translate text for webhook payload and fix conditional * add test for ooo_created webhooks * reset files * merge fix * fix test data test id * remove unused variable * only trigger for accepted memberships * remove unused variable --------- Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Co-authored-by: Keith Williams <keithwillcode@gmail.com> Co-authored-by: Omar López <zomars@me.com>
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import type { Webhook } from "@prisma/client";
|
|
import type { Prisma } from "@prisma/client";
|
|
import { v4 } from "uuid";
|
|
|
|
import { updateTriggerForExistingBookings } from "@calcom/features/webhooks/lib/scheduleTrigger";
|
|
import { prisma } from "@calcom/prisma";
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
|
|
|
import { TRPCError } from "@trpc/server";
|
|
|
|
import type { TCreateInputSchema } from "./create.schema";
|
|
|
|
type CreateOptions = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
input: TCreateInputSchema;
|
|
};
|
|
|
|
export const createHandler = async ({ ctx, input }: CreateOptions) => {
|
|
const { user } = ctx;
|
|
|
|
const webhookData: Prisma.WebhookCreateInput = {
|
|
id: v4(),
|
|
...input,
|
|
};
|
|
if (input.platform && user.role !== "ADMIN") {
|
|
throw new TRPCError({ code: "UNAUTHORIZED" });
|
|
}
|
|
|
|
// Add userId if platform, eventTypeId, and teamId are not provided
|
|
if (!input.platform && !input.eventTypeId && !input.teamId) {
|
|
webhookData.user = { connect: { id: user.id } };
|
|
}
|
|
|
|
let newWebhook: Webhook;
|
|
try {
|
|
newWebhook = await prisma.webhook.create({
|
|
data: webhookData,
|
|
});
|
|
} catch (error) {
|
|
// Avoid printing raw prisma error on frontend
|
|
throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: "Failed to create webhook" });
|
|
}
|
|
|
|
await updateTriggerForExistingBookings(newWebhook, [], newWebhook.eventTriggers);
|
|
|
|
return newWebhook;
|
|
};
|