bookingSeat could absolutely be unset at this point, resulting in Internal Error. (#7964)
parent
564862369f
commit
605f9c61f3
|
@ -927,14 +927,6 @@ async function handler(
|
||||||
|
|
||||||
// There are two paths here, reschedule a booking with seats and booking seats without reschedule
|
// There are two paths here, reschedule a booking with seats and booking seats without reschedule
|
||||||
if (rescheduleUid) {
|
if (rescheduleUid) {
|
||||||
const seatAttendee: Partial<Person> | null = bookingSeat?.attendee || null;
|
|
||||||
// Required for Typescript, these should always be set.
|
|
||||||
if (!seatAttendee || !bookingSeat || !rescheduleUid) {
|
|
||||||
throw new Error("Internal Error.");
|
|
||||||
}
|
|
||||||
|
|
||||||
seatAttendee.language = { translate: tAttendees, locale: bookingSeat?.attendee.locale ?? "en" };
|
|
||||||
|
|
||||||
// See if the new date has a booking already
|
// See if the new date has a booking already
|
||||||
const newTimeSlotBooking = await prisma.booking.findFirst({
|
const newTimeSlotBooking = await prisma.booking.findFirst({
|
||||||
where: {
|
where: {
|
||||||
|
@ -998,9 +990,16 @@ async function handler(
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
// If owner reschedules the event we want to update the entire booking
|
if (!bookingSeat) {
|
||||||
// Also if owner is rescheduling there should be no bookingSeat
|
// if no bookingSeat is given and the userId != owner, 401.
|
||||||
if (booking.user?.id === req.userId && !bookingSeat) {
|
// TODO: Next step; Evaluate ownership, what about teams?
|
||||||
|
if (booking.user?.id !== req.userId) {
|
||||||
|
throw new HttpError({ statusCode: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
// If owner reschedules the event we want to update the entire booking
|
||||||
|
// Also if owner is rescheduling there should be no bookingSeat
|
||||||
|
|
||||||
// If there is no booking during the new time slot then update the current booking to the new date
|
// If there is no booking during the new time slot then update the current booking to the new date
|
||||||
if (!newTimeSlotBooking) {
|
if (!newTimeSlotBooking) {
|
||||||
const newBooking: (Booking & { appsStatus?: AppsStatus[] }) | null = await prisma.booking.update({
|
const newBooking: (Booking & { appsStatus?: AppsStatus[] }) | null = await prisma.booking.update({
|
||||||
|
@ -1179,14 +1178,13 @@ async function handler(
|
||||||
return { ...resultBooking };
|
return { ...resultBooking };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// seatAttendee is null when the organizer is rescheduling.
|
||||||
|
const seatAttendee: Partial<Person> | null = bookingSeat?.attendee || null;
|
||||||
|
|
||||||
|
seatAttendee.language = { translate: tAttendees, locale: bookingSeat?.attendee.locale ?? "en" };
|
||||||
|
|
||||||
// If there is no booking then remove the attendee from the old booking and create a new one
|
// If there is no booking then remove the attendee from the old booking and create a new one
|
||||||
if (!newTimeSlotBooking) {
|
if (!newTimeSlotBooking) {
|
||||||
await prisma.bookingSeat.delete({
|
|
||||||
where: {
|
|
||||||
id: bookingSeat.id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await prisma.attendee.delete({
|
await prisma.attendee.delete({
|
||||||
where: {
|
where: {
|
||||||
id: seatAttendee.id,
|
id: seatAttendee.id,
|
||||||
|
|
Loading…
Reference in New Issue