fix: Location not changing when rescheduling (#20404)

* fix: location not chnging

* update

* update

* Update EventManager.ts

* update

* update

* Update reschedule.test.ts

---------

Co-authored-by: Tushar Bhatt <[email protected]>
Co-authored-by: sean-brydon <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-04-21 14:45:59 +01:00
1 parent d99ecde0e2
commit 7dfb71ca30
4 files changed
+193 -30

No files matched your search

+32 -23
View File
@@ -325,7 +325,7 @@ export default class EventManager {
meetingPassword: result.createdEvent?.password,
meetingUrl: result.createdEvent?.url,
externalCalendarId: result.externalId,
credentialId: result.credentialId ?? undefined,
...(result.credentialId && result.credentialId > 0 ? { credentialId: result.credentialId } : {}),
};
});
@@ -457,6 +457,7 @@ export default class EventManager {
id: true,
userId: true,
attendees: true,
location: true,
references: {
where: {
deleted: null,
@@ -490,7 +491,8 @@ export default class EventManager {
}
const results: Array<EventResult<Event>> = [];
const bookingReferenceChangedOrganizer: Array<PartialReference> = [];
const updatedBookingReferences: Array<PartialReference> = [];
const isLocationChanged = evt.location && booking.location && evt.location !== booking.location;
if (evt.requiresConfirmation) {
log.debug("RescheduleRequiresConfirmation: Deleting Event and Meeting for previous booking");
@@ -511,31 +513,37 @@ export default class EventManager {
const createdEvent = await this.create(originalEvt);
results.push(...createdEvent.results);
bookingReferenceChangedOrganizer.push(...createdEvent.referencesToCreate);
updatedBookingReferences.push(...createdEvent.referencesToCreate);
} else {
// If the reschedule doesn't require confirmation, we can "update" the events and meetings to new time.
const isDedicated = evt.location ? isDedicatedIntegration(evt.location) : null;
// If and only if event type is a dedicated meeting, update the dedicated video meeting.
if (isDedicated) {
const result = await this.updateVideoEvent(evt, booking);
const [updatedEvent] = Array.isArray(result.updatedEvent)
? result.updatedEvent
: [result.updatedEvent];
if (isLocationChanged) {
const updatedLocation = await this.updateLocation(evt, booking);
results.push(...updatedLocation.results);
updatedBookingReferences.push(...updatedLocation.referencesToCreate);
} else {
const isDedicated = evt.location ? isDedicatedIntegration(evt.location) : null;
// If and only if event type is a dedicated meeting, update the dedicated video meeting.
if (isDedicated) {
const result = await this.updateVideoEvent(evt, booking);
const [updatedEvent] = Array.isArray(result.updatedEvent)
? result.updatedEvent
: [result.updatedEvent];
if (updatedEvent) {
evt.videoCallData = updatedEvent;
evt.location = updatedEvent.url;
if (updatedEvent) {
evt.videoCallData = updatedEvent;
evt.location = updatedEvent.url;
}
results.push(result);
}
results.push(result);
}
const bookingCalendarReference = booking.references.find((reference) =>
reference.type.includes("_calendar")
);
// There was a case that booking didn't had any reference and we don't want to throw error on function
if (bookingCalendarReference) {
// Update all calendar events.
results.push(...(await this.updateAllCalendarEvents(evt, booking, newBookingId)));
const bookingCalendarReference = booking.references.find((reference) =>
reference.type.includes("_calendar")
);
// There was a case that booking didn't had any reference and we don't want to throw error on function
if (bookingCalendarReference) {
// Update all calendar events.
results.push(...(await this.updateAllCalendarEvents(evt, booking, newBookingId)));
}
}
results.push(...(await this.updateAllCRMEvents(evt, booking)));
@@ -560,7 +568,8 @@ export default class EventManager {
return {
results,
referencesToCreate: changedOrganizer ? bookingReferenceChangedOrganizer : [...booking.references],
referencesToCreate:
changedOrganizer || isLocationChanged ? updatedBookingReferences : [...booking.references],
};
}