Skip to content

Commit 5fbd342

Browse files
committed
bookingSeat could absolutely be unset at this point, resulting in Internal Error.
1 parent 5648623 commit 5fbd342

1 file changed

Lines changed: 15 additions & 17 deletions

File tree

packages/features/bookings/lib/handleNewBooking.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -927,14 +927,6 @@ async function handler(
927927

928928
// There are two paths here, reschedule a booking with seats and booking seats without reschedule
929929
if (rescheduleUid) {
930-
const seatAttendee: Partial<Person> | null = bookingSeat?.attendee || null;
931-
// Required for Typescript, these should always be set.
932-
if (!seatAttendee || !bookingSeat || !rescheduleUid) {
933-
throw new Error("Internal Error.");
934-
}
935-
936-
seatAttendee.language = { translate: tAttendees, locale: bookingSeat?.attendee.locale ?? "en" };
937-
938930
// See if the new date has a booking already
939931
const newTimeSlotBooking = await prisma.booking.findFirst({
940932
where: {
@@ -998,9 +990,16 @@ async function handler(
998990
}),
999991
};
1000992

1001-
// If owner reschedules the event we want to update the entire booking
1002-
// Also if owner is rescheduling there should be no bookingSeat
1003-
if (booking.user?.id === req.userId && !bookingSeat) {
993+
if (!bookingSeat) {
994+
// if no bookingSeat is given and the userId != owner, 401.
995+
// TODO: Next step; Evaluate ownership, what about teams?
996+
if (booking.user?.id !== req.userId) {
997+
throw new HttpError({ statusCode: 401 });
998+
}
999+
1000+
// If owner reschedules the event we want to update the entire booking
1001+
// Also if owner is rescheduling there should be no bookingSeat
1002+
10041003
// If there is no booking during the new time slot then update the current booking to the new date
10051004
if (!newTimeSlotBooking) {
10061005
const newBooking: (Booking & { appsStatus?: AppsStatus[] }) | null = await prisma.booking.update({
@@ -1179,14 +1178,13 @@ async function handler(
11791178
return { ...resultBooking };
11801179
}
11811180

1181+
// seatAttendee is null when the organizer is rescheduling.
1182+
const seatAttendee: Partial<Person> | null = bookingSeat?.attendee || null;
1183+
1184+
seatAttendee.language = { translate: tAttendees, locale: bookingSeat?.attendee.locale ?? "en" };
1185+
11821186
// If there is no booking then remove the attendee from the old booking and create a new one
11831187
if (!newTimeSlotBooking) {
1184-
await prisma.bookingSeat.delete({
1185-
where: {
1186-
id: bookingSeat.id,
1187-
},
1188-
});
1189-
11901188
await prisma.attendee.delete({
11911189
where: {
11921190
id: seatAttendee.id,

0 commit comments

Comments
 (0)