Replacing bookingAttendees for bookingUid (#8997)

pull/9036/head
alannnc 2023-05-22 02:30:24 -07:00 committed by GitHub
parent c8db177f7d
commit ff6c6ccec0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 6 deletions

View File

@ -72,7 +72,7 @@ const AvailableTimes: FC<AvailableTimesProps> = ({
slotUtcStartDate: slot.time,
eventTypeId,
slotUtcEndDate: dayjs(slot.time).utc().add(duration, "minutes").format(),
bookingAttendees: bookingAttendees || undefined,
bookingUid: slot.bookingUid,
});
};

View File

@ -237,7 +237,7 @@ const BookingPage = ({
eventTypeId: eventType.id,
slotUtcStartDate: dayjs(queryDate).utc().format(),
slotUtcEndDate: dayjs(queryDate).utc().add(parseInt(queryDuration), "minutes").format(),
bookingAttendees: currentSlotBooking ? currentSlotBooking.attendees.length : undefined,
bookingUid: currentSlotBooking?.uid,
});
}
};

View File

@ -21,7 +21,7 @@ interface ReserveSlotOptions {
export const reserveSlotHandler = async ({ ctx, input }: ReserveSlotOptions) => {
const { prisma, req, res } = ctx;
const uid = req?.cookies?.uid || uuid();
const { slotUtcStartDate, slotUtcEndDate, eventTypeId, bookingAttendees } = input;
const { slotUtcStartDate, slotUtcEndDate, eventTypeId, bookingUid } = input;
const releaseAt = dayjs.utc().add(parseInt(MINUTES_TO_BOOK), "minutes").format();
const eventType = await prisma.eventType.findUnique({
where: { id: eventTypeId },
@ -40,8 +40,13 @@ export const reserveSlotHandler = async ({ ctx, input }: ReserveSlotOptions) =>
// If this is a seated event then don't reserve a slot
if (eventType.seatsPerTimeSlot) {
// Check to see if this is the last attendee
if (bookingAttendees) {
const seatsLeft = eventType.seatsPerTimeSlot - bookingAttendees;
const bookingWithAttendees = await prisma.booking.findFirst({
where: { uid: bookingUid },
select: { attendees: true },
});
const bookingAttendeesLength = bookingWithAttendees?.attendees?.length;
if (bookingAttendeesLength) {
const seatsLeft = eventType.seatsPerTimeSlot - bookingAttendeesLength;
if (seatsLeft < 1) shouldReserveSlot = false;
} else {
// If there is no booking yet then don't reserve the slot

View File

@ -33,7 +33,7 @@ export const reserveSlotSchema = z
slotUtcStartDate: z.string(),
// endTime ISOString
slotUtcEndDate: z.string(),
bookingAttendees: z.number().optional(),
bookingUid: z.string().optional(),
})
.refine(
(data) => !!data.eventTypeId || !!data.slotUtcStartDate || !!data.slotUtcEndDate,