Fix reschedule not happening in calendar if two calendards are there (#2733)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
This commit is contained in:
Hariom Balhara
2022-05-12 09:33:15 +00:00
committed by GitHub
co-authored by kodiakhq[bot] Peer Richelsen
parent 574f9cb5d4
commit 7a08403636
3 changed files with 18 additions and 10 deletions
+1 -2
View File
@@ -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",
+11 -7
View File
@@ -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 {
+6 -1
View File
@@ -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 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);