fix: rescheduling in round robin (#14109)
* fix: rescheduling in round robin * chore: remove new calendar * chore: update logic * fix: simplify code * chore: update deletevents
This commit is contained in:
@@ -115,6 +115,7 @@ export default class EventManager {
|
||||
*/
|
||||
public async create(event: CalendarEvent): Promise<CreateUpdateResult> {
|
||||
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<CreateUpdateResult> {
|
||||
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,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user