Replaced `==` with `===` for the ADMIN role comparison to follow TypeScript best practices and match the project's coding conventions. Co-authored-by: Test User <test@example.com> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import { updateTriggerForExistingBookings } from "@calcom/features/webhooks/lib/scheduleTrigger";
|
|
import { prisma } from "@calcom/prisma";
|
|
import type { Prisma } from "@calcom/prisma/client";
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
|
|
|
import type { TDeleteInputSchema } from "./delete.schema";
|
|
|
|
type DeleteOptions = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
input: TDeleteInputSchema;
|
|
};
|
|
|
|
export const deleteHandler = async ({ ctx, input }: DeleteOptions) => {
|
|
const { id } = input;
|
|
|
|
const where: Prisma.WebhookWhereInput = { AND: [{ id: id }] };
|
|
|
|
if (Array.isArray(where.AND)) {
|
|
if (input.eventTypeId) {
|
|
where.AND.push({ eventTypeId: input.eventTypeId });
|
|
} else if (ctx.user.role === "ADMIN") {
|
|
where.AND.push({ OR: [{ platform: true }, { userId: ctx.user.id }] });
|
|
} else {
|
|
where.AND.push({ userId: ctx.user.id });
|
|
}
|
|
}
|
|
|
|
const webhookToDelete = await prisma.webhook.findFirst({
|
|
where,
|
|
});
|
|
|
|
if (webhookToDelete) {
|
|
await prisma.webhook.delete({
|
|
where: {
|
|
id: webhookToDelete.id,
|
|
},
|
|
});
|
|
|
|
await updateTriggerForExistingBookings(webhookToDelete, webhookToDelete.eventTriggers, []);
|
|
}
|
|
|
|
return {
|
|
id,
|
|
};
|
|
};
|