Merge pull request #113 from calcom/hotfix/webhook-booking-api

Hotfix webhook API booking issues
pull/9078/head
Syed Ali Shahbaz 2022-06-11 17:06:04 +05:30 committed by GitHub
commit 4ba0e7752d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 11 deletions

View File

@ -13,7 +13,6 @@ const schemaBookingBaseBodyParams = Booking.pick({
const schemaBookingCreateParams = z const schemaBookingCreateParams = z
.object({ .object({
uid: z.string(),
eventTypeId: z.number(), eventTypeId: z.number(),
title: z.string(), title: z.string(),
startTime: z.date().or(z.string()), startTime: z.date().or(z.string()),

View File

@ -1,7 +1,7 @@
import { WebhookTriggerEvents } from "@prisma/client"; import { WebhookTriggerEvents } from "@prisma/client";
import type { NextApiRequest, NextApiResponse } from "next"; import type { NextApiRequest, NextApiResponse } from "next";
import { v4 as uuidv4 } from "uuid";
import { getTranslation } from "@calcom/lib/server/i18n";
import prisma from "@calcom/prisma"; import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware"; import { withMiddleware } from "@lib/helpers/withMiddleware";
@ -83,7 +83,7 @@ async function createOrlistAllBookings(
return; return;
} }
safe.data.userId = userId; safe.data.userId = userId;
const data = await prisma.booking.create({ data: { ...safe.data } }); const data = await prisma.booking.create({ data: { uid: uuidv4(), ...safe.data } });
const booking = schemaBookingReadPublic.parse(data); const booking = schemaBookingReadPublic.parse(data);
if (booking) { if (booking) {
@ -92,13 +92,9 @@ async function createOrlistAllBookings(
const eventType = await prisma.eventType const eventType = await prisma.eventType
.findUnique({ where: { id: booking.eventTypeId as number } }) .findUnique({ where: { id: booking.eventTypeId as number } })
.then((data) => schemaEventTypeReadPublic.parse(data)) .then((data) => schemaEventTypeReadPublic.parse(data))
.catch((error: Error) => .catch((e: Error) => {
res.status(404).json({ console.error(`Event type with ID: ${booking.eventTypeId} not found`, e);
message: `EventType with id: ${booking.eventTypeId} not found`, });
error,
})
);
const fallbackTfunction = await getTranslation("en", "common");
const evt = { const evt = {
type: eventType?.title || booking.title, type: eventType?.title || booking.title,
title: booking.title, title: booking.title,
@ -112,7 +108,6 @@ async function createOrlistAllBookings(
email: "", email: "",
timeZone: "", timeZone: "",
language: { language: {
translate: fallbackTfunction,
locale: "en", locale: "en",
}, },
}, },