From 0fc79f93de21be2cc1ee5546be056f3cceb53cab Mon Sep 17 00:00:00 2001 From: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Date: Thu, 21 Mar 2024 17:05:34 +0530 Subject: [PATCH] fix: rescheduling in round robin (#14109) * fix: rescheduling in round robin * chore: remove new calendar * chore: update logic * fix: simplify code * chore: update deletevents --- packages/core/EventManager.ts | 20 ++++++++++++------- .../features/bookings/lib/handleNewBooking.ts | 19 +++++++++++------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/packages/core/EventManager.ts b/packages/core/EventManager.ts index 719d1b9949..8bae88b38c 100644 --- a/packages/core/EventManager.ts +++ b/packages/core/EventManager.ts @@ -115,6 +115,7 @@ export default class EventManager { */ public async create(event: CalendarEvent): Promise { const evt = processLocation(event); + // Fallback to cal video if no location is set if (!evt.location) { // See if cal video is enabled & has keys @@ -328,7 +329,7 @@ export default class EventManager { rescheduleUid: string, newBookingId?: number, changedOrganizer?: boolean, - newDestinationCalendar?: DestinationCalendar[] | null + previousHostDestinationCalendar?: DestinationCalendar[] | null ): Promise { const originalEvt = processLocation(event); const evt = cloneDeep(originalEvt); @@ -380,16 +381,21 @@ export default class EventManager { if (evt.requiresConfirmation) { log.debug("RescheduleRequiresConfirmation: Deleting Event and Meeting for previous booking"); // As the reschedule requires confirmation, we can't update the events and meetings to new time yet. So, just delete them and let it be handled when organizer confirms the booking. - await this.deleteEventsAndMeetings({ booking, event }); + await this.deleteEventsAndMeetings({ + booking, + event: { ...event, destinationCalendar: previousHostDestinationCalendar }, + }); } else { if (changedOrganizer) { log.debug("RescheduleOrganizerChanged: Deleting Event and Meeting for previous booking"); - await this.deleteEventsAndMeetings({ booking, event }); + await this.deleteEventsAndMeetings({ + booking, + event: { ...event, destinationCalendar: previousHostDestinationCalendar }, + }); log.debug("RescheduleOrganizerChanged: Creating Event and Meeting for for new booking"); - const newEvent = { ...evt, destinationCalendar: newDestinationCalendar }; - const createdEvent = await this.create(newEvent); + const createdEvent = await this.create(originalEvt); results.push(...createdEvent.results); bookingReferenceChangedOrganizer.push(...createdEvent.referencesToCreate); } else { @@ -453,14 +459,14 @@ export default class EventManager { const videoReferences = booking.references.filter((reference) => reference.type.includes("_video")); log.debug("deleteEventsAndMeetings", safeStringify({ calendarReferences, videoReferences })); const calendarPromises = calendarReferences.map(async (bookingCalendarReference) => { - return await this.deleteCalendarEventForBookingReference({ + return this.deleteCalendarEventForBookingReference({ bookingCalendarReference, event, }); }); const videoPromises = videoReferences.map(async (bookingVideoReference) => { - return await this.deleteVideoEventForBookingReference({ + return this.deleteVideoEventForBookingReference({ bookingVideoReference, }); }); diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index 8c406bc23f..2094c88472 100644 --- a/packages/features/bookings/lib/handleNewBooking.ts +++ b/packages/features/bookings/lib/handleNewBooking.ts @@ -1747,18 +1747,22 @@ async function handler( evt = addVideoCallDataToEvent(originalRescheduledBooking.references, evt); - const newDestinationCalendar = evt.destinationCalendar; - - evt.destinationCalendar = originalRescheduledBooking?.destinationCalendar + // If organizer is changed in RR event then we need to delete the previous host destination calendar events + const previousHostDestinationCalendar = originalRescheduledBooking?.destinationCalendar ? [originalRescheduledBooking?.destinationCalendar] - : originalRescheduledBooking?.user?.destinationCalendar - ? [originalRescheduledBooking?.user.destinationCalendar] - : evt.destinationCalendar; + : []; if (changedOrganizer) { evt.title = getEventName(eventNameObject); // location might changed and will be new created in eventManager.create (organizer default location) evt.videoCallData = undefined; + // To prevent "The requested identifier already exists" error while updating event, we need to remove iCalUID + evt.iCalUID = undefined; + } else { + // In case of rescheduling, we need to keep the previous host destination calendar + evt.destinationCalendar = originalRescheduledBooking?.destinationCalendar + ? [originalRescheduledBooking?.destinationCalendar] + : evt.destinationCalendar; } const updateManager = await eventManager.reschedule( @@ -1766,7 +1770,7 @@ async function handler( originalRescheduledBooking.uid, undefined, changedOrganizer, - newDestinationCalendar + previousHostDestinationCalendar ); // This gets overridden when updating the event - to check if notes have been hidden or not. We just reset this back @@ -1864,6 +1868,7 @@ async function handler( metadata.hangoutLink || results[0].createdEvent?.url || organizerOrFirstDynamicGroupMemberDefaultLocationUrl || + getVideoCallUrlFromCalEvent(evt) || videoCallUrl; }