From f3e8bed1cfb81f30190a251df099f2902b3f6c26 Mon Sep 17 00:00:00 2001 From: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Date: Thu, 16 Mar 2023 14:12:30 -0400 Subject: [PATCH] Fix dynamic bookings overwriting users (#7699) * Move sorting dynamic user list * Remove console logs --- .../features/bookings/lib/handleNewBooking.ts | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index bf1e7853b3..92df0e29bf 100644 --- a/packages/features/bookings/lib/handleNewBooking.ts +++ b/packages/features/bookings/lib/handleNewBooking.ts @@ -613,6 +613,20 @@ async function handler( : user.isFixed || eventType.schedulingType !== SchedulingType.ROUND_ROBIN, })); + let locationBodyString = location; + let defaultLocationUrl = undefined; + if (dynamicUserList.length > 1) { + users = users.sort((a, b) => { + const aIndex = (a.username && dynamicUserList.indexOf(a.username)) || 0; + const bIndex = (b.username && dynamicUserList.indexOf(b.username)) || 0; + return aIndex - bIndex; + }); + const firstUsersMetadata = userMetadataSchema.parse(users[0].metadata); + const app = getAppFromSlug(firstUsersMetadata?.defaultConferencingApp?.appSlug); + locationBodyString = app?.appData?.location?.type || locationBodyString; + defaultLocationUrl = firstUsersMetadata?.defaultConferencingApp?.appLink; + } + if (eventType && eventType.hasOwnProperty("bookingLimits") && eventType?.bookingLimits) { const startAsDate = dayjs(reqBody.start).toDate(); await checkBookingLimits(eventType.bookingLimits, startAsDate, eventType.id); @@ -707,20 +721,6 @@ async function handler( const seed = `${organizerUser.username}:${dayjs(reqBody.start).utc().format()}:${new Date().getTime()}`; const uid = translator.fromUUID(uuidv5(seed, uuidv5.URL)); - let locationBodyString = location; - let defaultLocationUrl = undefined; - if (dynamicUserList.length > 1) { - users = users.sort((a, b) => { - const aIndex = (a.username && dynamicUserList.indexOf(a.username)) || 0; - const bIndex = (b.username && dynamicUserList.indexOf(b.username)) || 0; - return aIndex - bIndex; - }); - const firstUsersMetadata = userMetadataSchema.parse(users[0].metadata); - const app = getAppFromSlug(firstUsersMetadata?.defaultConferencingApp?.appSlug); - locationBodyString = app?.appData?.location?.type || locationBodyString; - defaultLocationUrl = firstUsersMetadata?.defaultConferencingApp?.appLink; - } - const bookingLocation = getLocationValueForDB(locationBodyString, eventType.locations); const customInputs = getCustomInputsResponses(reqBody, eventType.customInputs); const teamMemberPromises =