Fix dynamic bookings overwriting users (#7699)

* Move sorting dynamic user list

* Remove console logs
pull/7782/head^2
Joe Au-Yeung 2023-03-16 14:12:30 -04:00 committed by GitHub
parent 750362c0cf
commit f3e8bed1cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 14 deletions

View File

@ -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 =