chore: Log availability snapshot when booking is created (#22782)
* Add userAvailability type * Add user availability to return value of getUsersAvailability * Log availabilitySnapshot when booking is created * Type fix
This commit is contained in:
@@ -658,6 +658,7 @@ async function handler(
|
||||
|
||||
let luckyUserResponse;
|
||||
let isFirstSeat = true;
|
||||
let availableUsers: IsFixedAwareUser[] = [];
|
||||
|
||||
if (eventType.seatsPerTimeSlot) {
|
||||
const booking = await prisma.booking.findFirst({
|
||||
@@ -757,7 +758,6 @@ async function handler(
|
||||
}
|
||||
|
||||
if (!input.bookingData.allRecurringDates || input.bookingData.isFirstRecurringSlot) {
|
||||
let availableUsers: IsFixedAwareUser[] = [];
|
||||
try {
|
||||
availableUsers = await ensureAvailableUsers(
|
||||
{ ...eventTypeWithUsers, users: [...qualifiedRRUsers, ...fixedUsers] as IsFixedAwareUser[] },
|
||||
@@ -1391,6 +1391,12 @@ async function handler(
|
||||
if (booking?.userId) {
|
||||
const usersRepository = new UsersRepository();
|
||||
await usersRepository.updateLastActiveAt(booking.userId);
|
||||
const organizerUserAvailability = availableUsers.find((user) => user.id === booking?.userId);
|
||||
|
||||
logger.info(`Booking created`, {
|
||||
bookingUid: booking.uid,
|
||||
availabilitySnapshot: organizerUserAvailability?.availabilityData,
|
||||
});
|
||||
}
|
||||
|
||||
// If it's a round robin event, record the reason for the host assignment
|
||||
|
||||
@@ -99,6 +99,7 @@ const _ensureAvailableUsers = async (
|
||||
afterEventBuffer: eventType.afterEventBuffer,
|
||||
bypassBusyCalendarTimes: false,
|
||||
shouldServeCache,
|
||||
withSource: true,
|
||||
},
|
||||
initialData: {
|
||||
eventType,
|
||||
@@ -210,7 +211,8 @@ const _ensureAvailableUsers = async (
|
||||
}
|
||||
}
|
||||
|
||||
usersAvailability.forEach(({ oooExcludedDateRanges: dateRanges, busy: bufferedBusyTimes }, index) => {
|
||||
usersAvailability.forEach((userAvailability, index) => {
|
||||
const { oooExcludedDateRanges: dateRanges, busy: bufferedBusyTimes } = userAvailability;
|
||||
const user = eventType.users[index];
|
||||
|
||||
loggerWithEventDetails.debug(
|
||||
@@ -239,7 +241,7 @@ const _ensureAvailableUsers = async (
|
||||
eventLength: duration,
|
||||
});
|
||||
if (!foundConflict) {
|
||||
availableUsers.push(user);
|
||||
availableUsers.push({ ...user, availabilityData: userAvailability });
|
||||
}
|
||||
} catch (error) {
|
||||
loggerWithEventDetails.error("Unable set isAvailableToBeBooked. Using true. ", error);
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { TFunction } from "i18next";
|
||||
|
||||
import type { EventTypeAppsList } from "@calcom/app-store/utils";
|
||||
import type { PaymentAppData } from "@calcom/lib/getPaymentAppData";
|
||||
import type { GetUserAvailabilityResult } from "@calcom/lib/getUserAvailability";
|
||||
import type { userSelect } from "@calcom/prisma";
|
||||
import type { SelectedCalendar } from "@calcom/prisma/client";
|
||||
import type { CredentialForCalendarService } from "@calcom/types/Credential";
|
||||
@@ -40,6 +41,7 @@ export type IsFixedAwareUser = User & {
|
||||
weight?: number;
|
||||
userLevelSelectedCalendars: SelectedCalendar[];
|
||||
allSelectedCalendars: SelectedCalendar[];
|
||||
availabilityData?: GetUserAvailabilityResult;
|
||||
};
|
||||
|
||||
export type { PaymentAppData };
|
||||
|
||||
@@ -266,7 +266,7 @@ export type CurrentSeats = Awaited<ReturnType<typeof _getCurrentSeats>>;
|
||||
|
||||
export const getCurrentSeats = withReporting(_getCurrentSeats, "getCurrentSeats");
|
||||
|
||||
type GetUserAvailabilityResult = ReturnType<typeof _getUserAvailability>;
|
||||
export type GetUserAvailabilityResult = Awaited<ReturnType<typeof _getUserAvailability>>;
|
||||
|
||||
/** This should be called getUsersWorkingHoursAndBusySlots (...and remaining seats, and final timezone) */
|
||||
const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseAndEverythingElse(
|
||||
|
||||
Reference in New Issue
Block a user