Merge pull request #172 from calcom/fix/invalid-eventtypeid

Recurring event booking: invalid eventTypeId
pull/9078/head
Omar López 2022-10-07 10:59:14 -06:00 committed by GitHub
commit 85890a6acb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -64,14 +64,15 @@ async function handler(
const eventTypeDb = await prisma.eventType.findUnique({
where: { id: booking.eventTypeId },
});
if (!eventTypeDb) throw new HttpError({ statusCode: 400, message: "Invalid eventTypeId." });
const eventType = schemaEventTypeReadPublic.parse(eventTypeDb);
let bookings: z.infer<typeof schemaBookingReadPublic>[];
if (!eventType) throw new HttpError({ statusCode: 400, message: "Could not create new booking" });
if (eventType.recurringEvent) {
console.log("Event type has recurring configuration");
if (!booking.recurringCount) throw new HttpError({ statusCode: 400, message: "Missing recurringCount" });
if (!booking.recurringCount) throw new HttpError({ statusCode: 400, message: "Missing recurringCount." });
if (eventType.recurringEvent.count && booking.recurringCount > eventType?.recurringEvent.count) {
throw new HttpError({ statusCode: 400, message: "Invalid recurringCount" });
throw new HttpError({ statusCode: 400, message: "Invalid recurringCount." });
}
// Event type is recurring, ceating each booking
const recurringEventId = uuidv4();

View File

@ -28,7 +28,8 @@ describe("POST /api/bookings", () => {
expect(res._getStatusCode()).toBe(400);
expect(JSON.parse(res._getData())).toEqual(
expect.objectContaining({
message: "Booking body is invalid.",
message:
"'invalid_type' in 'eventTypeId': Required; 'invalid_type' in 'title': Required; 'invalid_type' in 'startTime': Required; 'invalid_type' in 'startTime': Required; 'invalid_type' in 'endTime': Required; 'invalid_type' in 'endTime': Required",
})
);
});
@ -45,7 +46,7 @@ describe("POST /api/bookings", () => {
prisma,
});
//prismaMock.eventType.findUnique.mockResolvedValue(null);
prismaMock.eventType.findUnique.mockResolvedValue(null);
await handler(req, res);