Fix unconfirmed booking marked as confirmed in DB (#5141)

pull/5146/head^2
Hariom Balhara 2022-10-21 11:18:24 +05:30 committed by GitHub
parent 5f78eceb89
commit 0344130f68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -245,7 +245,7 @@ async function ensureAvailableUsers(
return availableUsers; return availableUsers;
} }
async function handler(req: NextApiRequest & { userId?: number }) { async function handler(req: NextApiRequest & { userId?: number | undefined }) {
const { userId } = req; const { userId } = req;
const { const {
@ -600,7 +600,8 @@ async function handler(req: NextApiRequest & { userId?: number }) {
// If the user is not the owner of the event, new booking should be always pending. // If the user is not the owner of the event, new booking should be always pending.
// Otherwise, an owner rescheduling should be always accepted. // Otherwise, an owner rescheduling should be always accepted.
const userReschedulingIsOwner = originalRescheduledBooking?.user?.id === userId; // Before comparing make sure that userId is set, otherwise undefined === undefined
const userReschedulingIsOwner = userId && originalRescheduledBooking?.user?.id === userId;
const isConfirmedByDefault = const isConfirmedByDefault =
(!eventType.requiresConfirmation && !stripeAppData.price) || userReschedulingIsOwner; (!eventType.requiresConfirmation && !stripeAppData.price) || userReschedulingIsOwner;
const newBookingData: Prisma.BookingCreateInput = { const newBookingData: Prisma.BookingCreateInput = {
@ -840,6 +841,7 @@ async function handler(req: NextApiRequest & { userId?: number }) {
} }
} }
// FIXME: instead of requiresConfirmation, we should check if isConfirmedByDefault is set or not.
if (eventType.requiresConfirmation && !rescheduleUid && noEmail !== true) { if (eventType.requiresConfirmation && !rescheduleUid && noEmail !== true) {
await sendOrganizerRequestEmail({ ...evt, additionalNotes }); await sendOrganizerRequestEmail({ ...evt, additionalNotes });
await sendAttendeeRequestEmail({ ...evt, additionalNotes }, attendeesList[0]); await sendAttendeeRequestEmail({ ...evt, additionalNotes }, attendeesList[0]);
@ -916,6 +918,7 @@ async function handler(req: NextApiRequest & { userId?: number }) {
rescheduleUid, rescheduleUid,
metadata: reqBody.metadata, metadata: reqBody.metadata,
eventTypeId, eventTypeId,
//FIXME: FOr consistency b/w webhook and actual DB state, it should use isConfirmedByDefault here
status: eventType.requiresConfirmation ? "PENDING" : "ACCEPTED", status: eventType.requiresConfirmation ? "PENDING" : "ACCEPTED",
}).catch((e) => { }).catch((e) => {
console.error(`Error executing webhook for event: ${eventTrigger}, URL: ${sub.subscriberUrl}`, e); console.error(`Error executing webhook for event: ${eventTrigger}, URL: ${sub.subscriberUrl}`, e);