Merge pull request #172 from calcom/fix/invalid-eventtypeid
Recurring event booking: invalid eventTypeIdpull/9078/head
commit
85890a6acb
|
@ -64,14 +64,15 @@ async function handler(
|
||||||
const eventTypeDb = await prisma.eventType.findUnique({
|
const eventTypeDb = await prisma.eventType.findUnique({
|
||||||
where: { id: booking.eventTypeId },
|
where: { id: booking.eventTypeId },
|
||||||
});
|
});
|
||||||
|
if (!eventTypeDb) throw new HttpError({ statusCode: 400, message: "Invalid eventTypeId." });
|
||||||
const eventType = schemaEventTypeReadPublic.parse(eventTypeDb);
|
const eventType = schemaEventTypeReadPublic.parse(eventTypeDb);
|
||||||
let bookings: z.infer<typeof schemaBookingReadPublic>[];
|
let bookings: z.infer<typeof schemaBookingReadPublic>[];
|
||||||
if (!eventType) throw new HttpError({ statusCode: 400, message: "Could not create new booking" });
|
if (!eventType) throw new HttpError({ statusCode: 400, message: "Could not create new booking" });
|
||||||
if (eventType.recurringEvent) {
|
if (eventType.recurringEvent) {
|
||||||
console.log("Event type has recurring configuration");
|
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) {
|
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
|
// Event type is recurring, ceating each booking
|
||||||
const recurringEventId = uuidv4();
|
const recurringEventId = uuidv4();
|
||||||
|
|
|
@ -28,7 +28,8 @@ describe("POST /api/bookings", () => {
|
||||||
expect(res._getStatusCode()).toBe(400);
|
expect(res._getStatusCode()).toBe(400);
|
||||||
expect(JSON.parse(res._getData())).toEqual(
|
expect(JSON.parse(res._getData())).toEqual(
|
||||||
expect.objectContaining({
|
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,
|
prisma,
|
||||||
});
|
});
|
||||||
|
|
||||||
//prismaMock.eventType.findUnique.mockResolvedValue(null);
|
prismaMock.eventType.findUnique.mockResolvedValue(null);
|
||||||
|
|
||||||
await handler(req, res);
|
await handler(req, res);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue