Scheduling infrastructure for absolutely everyone.
Fix reschedule not happening in calendar if two calendards are there (#2733)
Hariom Balhara7a0840363672
diff --git a/apps/web/pages/api/book/event.ts b/apps/web/pages/api/book/event.tsindex 1c5b3d41d40..e2f88a180e5 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.tsindex 9159dd6c529..b3fbfae1a74 100644--- a/packages/core/CalendarManager.ts+++ b/packages/core/CalendarManager.ts@@ -132,15 +132,19 @@ export const updateEvent = async (): Promise<EventResult> => {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.tsindex fdfb1c0c428..6e90a130f13 100644--- a/packages/core/EventManager.ts+++ b/packages/core/EventManager.ts@@ -345,8 +345,13 @@ export default class EventManager {booking: PartialBooking): Promise<Array<EventResult>> {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 oneconst 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);