diff --git a/apps/web/pages/api/book/event.ts b/apps/web/pages/api/book/event.ts index 1c5b3d41d4..e2f88a180e 100644 --- a/apps/web/pages/api/book/event.ts +++ b/apps/web/pages/api/book/event.ts @@ -646,8 +646,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) results = updateManager.results; referencesToCreate = updateManager.referencesToCreate; - - if (results.length > 0 && results.every((res) => !res.success)) { + if (results.length > 0 && results.some((res) => !res.success)) { const error = { errorCode: "BookingReschedulingMeetingFailed", message: "Booking Rescheduling failed", diff --git a/packages/core/CalendarManager.ts b/packages/core/CalendarManager.ts index 9159dd6c52..b3fbfae1a7 100644 --- a/packages/core/CalendarManager.ts +++ b/packages/core/CalendarManager.ts @@ -132,15 +132,19 @@ export const updateEvent = async ( ): Promise => { const uid = getUid(calEvent); const calendar = getCalendar(credential); - let success = true; - + let success = false; + if (bookingRefUid === "") { + log.error("updateEvent failed", "bookingRefUid is empty", calEvent, credential); + } const updatedResult = calendar && bookingRefUid - ? await calendar.updateEvent(bookingRefUid, calEvent).catch((e) => { - log.error("updateEvent failed", e, calEvent); - success = false; - return undefined; - }) + ? await calendar + .updateEvent(bookingRefUid, calEvent) + .then(() => (success = true)) + .catch((e) => { + log.error("updateEvent failed", e, calEvent); + return undefined; + }) : undefined; return { diff --git a/packages/core/EventManager.ts b/packages/core/EventManager.ts index fdfb1c0c42..6e90a130f1 100644 --- a/packages/core/EventManager.ts +++ b/packages/core/EventManager.ts @@ -345,8 +345,13 @@ export default class EventManager { booking: PartialBooking ): Promise> { return async.mapLimit(this.calendarCredentials, 5, async (credential: Credential) => { + // HACK: + // Right now if two calendars are connected and a booking is created it has two bookingReferences, one is having uid null and the other is having valid uid. + // I don't know why yet - But we should work on fixing that. But even after the fix as there can be multiple references in an existing booking the following ref.uid check would still be required + // We should ignore the one with uid null, the other one is valid. + // Also, we should store(if not already) that which is the calendarCredential for the valid bookingReference, instead of going through all credentials one by one const bookingRefUid = booking - ? booking.references.filter((ref) => ref.type === credential.type)[0]?.uid + ? booking.references.filter((ref) => ref.type === credential.type && !!ref.uid)[0]?.uid : null; return updateEvent(credential, event, bookingRefUid);