Skip to content

Commit 9b3bbb9

Browse files
authored
fix: unify webhook ID resolution across handlers (calcom#28701)
1 parent 2e5643e commit 9b3bbb9

6 files changed

Lines changed: 10 additions & 9 deletions

File tree

packages/trpc/server/routers/viewer/webhook/create.handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ export const createHandler = async ({ ctx, input }: CreateOptions) => {
3333
});
3434
}
3535

36+
const { webhookId: _webhookId, ...inputWithoutWebhookId } = input;
3637
const webhookData: Prisma.WebhookCreateInput = {
3738
id: v4(),
38-
...input,
39+
...inputWithoutWebhookId,
3940
};
4041
if (input.platform && user.role !== "ADMIN") {
4142
throw new TRPCError({ code: "UNAUTHORIZED" });

packages/trpc/server/routers/viewer/webhook/edit.handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type EditOptions = {
2121
};
2222

2323
export const editHandler = async ({ input, ctx }: EditOptions) => {
24-
const { id, ...data } = input;
24+
const { id, webhookId: _webhookId, ...data } = input;
2525

2626
const webhook = await prisma.webhook.findUnique({
2727
where: {

packages/trpc/server/routers/viewer/webhook/get.handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ type GetOptions = {
1111

1212
export const getHandler = async ({ ctx: _ctx, input }: GetOptions) => {
1313
const { repository: webhookRepository } = getWebhookFeature();
14-
return await webhookRepository.findByWebhookId(input.webhookId);
14+
return await webhookRepository.findByWebhookId(input.id || input.webhookId);
1515
};

packages/trpc/server/routers/viewer/webhook/get.schema.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { z } from "zod";
22

33
import { webhookIdAndEventTypeIdSchema } from "./types";
44

5-
export const ZGetInputSchema = webhookIdAndEventTypeIdSchema.extend({
6-
webhookId: z.string().optional(),
7-
});
5+
export const ZGetInputSchema = webhookIdAndEventTypeIdSchema;
86

97
export type TGetInputSchema = z.infer<typeof ZGetInputSchema>;

packages/trpc/server/routers/viewer/webhook/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { z } from "zod";
44
export const webhookIdAndEventTypeIdSchema = z.object({
55
// Webhook ID
66
id: z.string().optional(),
7+
webhookId: z.string().optional(),
78
eventTypeId: z.number().optional(),
89
teamId: z.number().optional(),
910
});

packages/trpc/server/routers/viewer/webhook/util.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ export const createWebhookPbacProcedure = (
2222
// Endpoints that just read the logged in user's data - like 'list' don't necessarily have any input
2323
if (!input) return next();
2424

25-
const { id, teamId, eventTypeId } = input;
25+
const { id, webhookId, teamId, eventTypeId } = input;
26+
const lookupId = id || webhookId;
2627
const permissionCheckService = new PermissionCheckService();
2728

28-
if (id) {
29+
if (lookupId) {
2930
// Check if user is authorized to edit webhook
3031
const webhook = await prisma.webhook.findUnique({
31-
where: { id },
32+
where: { id: lookupId },
3233
select: {
3334
id: true,
3435
userId: true,

0 commit comments

Comments
 (0)