Merge pull request #113 from calcom/hotfix/webhook-booking-api
Hotfix webhook API booking issuespull/9078/head
commit
4ba0e7752d
|
@ -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()),
|
||||||
|
|
|
@ -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",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue