test: Booking flow App failure and ics file tests and improved logging (#11646)
This commit is contained in:
1 parent
07bfaec24e
commit
3ca7456885
17 files changed
+513
-239
No files matched your search
@@ -42,7 +42,7 @@ export const getCalendar = async (credential: CredentialPayload | null): Promise
|
||||
log.warn(`calendar of type ${calendarType} is not implemented`);
|
||||
return null;
|
||||
}
|
||||
log.info("calendarApp", calendarApp.lib.CalendarService);
|
||||
log.info("Got calendarApp", calendarApp.lib.CalendarService);
|
||||
const CalendarService = calendarApp.lib.CalendarService;
|
||||
return new CalendarService(credential);
|
||||
};
|
||||
@@ -256,7 +256,10 @@ export const createEvent = async (
|
||||
if (error?.calError) {
|
||||
calError = error.calError;
|
||||
}
|
||||
log.error("createEvent failed", JSON.stringify(error), calEvent);
|
||||
log.error(
|
||||
"createEvent failed",
|
||||
safeStringify({ error, calEvent: getPiiFreeCalendarEvent(calEvent) })
|
||||
);
|
||||
// @TODO: This code will be off till we can investigate an error with it
|
||||
//https://github.com/calcom/cal.com/issues/3949
|
||||
// await sendBrokenIntegrationEmail(calEvent, "calendar");
|
||||
@@ -266,7 +269,13 @@ export const createEvent = async (
|
||||
if (!creationResult) {
|
||||
logger.silly("createEvent failed", { success, uid, creationResult, originalEvent: calEvent, calError });
|
||||
}
|
||||
|
||||
log.debug(
|
||||
"Created calendar event",
|
||||
JSON.stringify({
|
||||
calEvent: getPiiFreeCalendarEvent(calEvent),
|
||||
creationResult,
|
||||
})
|
||||
);
|
||||
return {
|
||||
appName: credential.appId || "",
|
||||
type: credential.type,
|
||||
|
||||
@@ -10,6 +10,7 @@ import { appKeysSchema as calVideoKeysSchema } from "@calcom/app-store/dailyvide
|
||||
import { getEventLocationTypeFromApp, MeetLocationType } from "@calcom/app-store/locations";
|
||||
import getApps from "@calcom/app-store/utils";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { getPiiFreeUser } from "@calcom/lib/piiFreeData";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||
@@ -27,6 +28,7 @@ import type {
|
||||
import { createEvent, updateEvent } from "./CalendarManager";
|
||||
import { createMeeting, updateMeeting } from "./videoClient";
|
||||
|
||||
const log = logger.getChildLogger({ prefix: ["EventManager"] });
|
||||
export const isDedicatedIntegration = (location: string): boolean => {
|
||||
return location !== MeetLocationType && location.includes("integrations:");
|
||||
};
|
||||
@@ -81,7 +83,7 @@ export default class EventManager {
|
||||
* @param user
|
||||
*/
|
||||
constructor(user: EventManagerUser) {
|
||||
logger.silly("Initializing EventManager", JSON.stringify({ user }));
|
||||
log.silly("Initializing EventManager", safeStringify({ user: getPiiFreeUser(user) }));
|
||||
const appCredentials = getApps(user.credentials, true).flatMap((app) =>
|
||||
app.credentials.map((creds) => ({ ...creds, appName: app.name }))
|
||||
);
|
||||
@@ -124,6 +126,7 @@ export default class EventManager {
|
||||
const [mainHostDestinationCalendar] =
|
||||
(evt.destinationCalendar as [undefined | NonNullable<typeof evt.destinationCalendar>[number]]) ?? [];
|
||||
if (evt.location === MeetLocationType && mainHostDestinationCalendar?.integration !== "google_calendar") {
|
||||
log.warn("Falling back to Cal Video integration as Google Calendar not installed");
|
||||
evt["location"] = "integrations:daily";
|
||||
}
|
||||
const isDedicated = evt.location ? isDedicatedIntegration(evt.location) : null;
|
||||
@@ -362,7 +365,7 @@ export default class EventManager {
|
||||
[] as DestinationCalendar[]
|
||||
);
|
||||
for (const destination of destinationCalendars) {
|
||||
logger.silly("Creating Calendar event", JSON.stringify({ destination }));
|
||||
log.silly("Creating Calendar event", JSON.stringify({ destination }));
|
||||
if (destination.credentialId) {
|
||||
let credential = this.calendarCredentials.find((c) => c.id === destination.credentialId);
|
||||
if (!credential) {
|
||||
@@ -402,7 +405,7 @@ export default class EventManager {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.silly(
|
||||
log.silly(
|
||||
"No destination Calendar found, falling back to first connected calendar",
|
||||
safeStringify({
|
||||
calendarCredentials: this.calendarCredentials,
|
||||
@@ -416,7 +419,7 @@ export default class EventManager {
|
||||
const [credential] = this.calendarCredentials.filter((cred) => !cred.type.endsWith("other_calendar"));
|
||||
if (credential) {
|
||||
const createdEvent = await createEvent(credential, event);
|
||||
logger.silly("Created Calendar event", { createdEvent });
|
||||
log.silly("Created Calendar event", safeStringify({ createdEvent }));
|
||||
if (createdEvent) {
|
||||
createdEvents.push(createdEvent);
|
||||
}
|
||||
@@ -465,7 +468,7 @@ export default class EventManager {
|
||||
* @todo remove location from event types that has missing credentials
|
||||
* */
|
||||
if (!videoCredential) {
|
||||
logger.warn(
|
||||
log.warn(
|
||||
'Falling back to "daily" video integration for event with location: ' +
|
||||
event.location +
|
||||
" because credential is missing for the app"
|
||||
@@ -513,7 +516,7 @@ export default class EventManager {
|
||||
): Promise<Array<EventResult<NewCalendarEventType>>> {
|
||||
let calendarReference: PartialReference[] | undefined = undefined,
|
||||
credential;
|
||||
logger.silly("updateAllCalendarEvents", JSON.stringify({ event, booking, newBookingId }));
|
||||
log.silly("updateAllCalendarEvents", JSON.stringify({ event, booking, newBookingId }));
|
||||
try {
|
||||
// If a newBookingId is given, update that calendar event
|
||||
let newBooking;
|
||||
@@ -575,7 +578,7 @@ export default class EventManager {
|
||||
(credential) => credential.type === reference?.type
|
||||
);
|
||||
for (const credential of credentials) {
|
||||
logger.silly("updateAllCalendarEvents-credential", JSON.stringify({ credentials }));
|
||||
log.silly("updateAllCalendarEvents-credential", JSON.stringify({ credentials }));
|
||||
result.push(updateEvent(credential, event, bookingRefUid, calenderExternalId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { SelectedCalendar } from "@prisma/client";
|
||||
import { getCalendar } from "@calcom/app-store/_utils/getCalendar";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { getPiiFreeCredential, getPiiFreeSelectedCalendar } from "@calcom/lib/piiFreeData";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { performance } from "@calcom/lib/server/perfObserver";
|
||||
import type { EventBusyDate } from "@calcom/types/Calendar";
|
||||
import type { CredentialPayload } from "@calcom/types/Credential";
|
||||
@@ -35,6 +36,13 @@ const getCalendarsEvents = async (
|
||||
const selectedCalendarIds = passedSelectedCalendars.map((sc) => sc.externalId);
|
||||
/** If we don't then we actually fetch external calendars (which can be very slow) */
|
||||
performance.mark("eventBusyDatesStart");
|
||||
log.debug(
|
||||
`Getting availability for`,
|
||||
safeStringify({
|
||||
calendarService: c.constructor.name,
|
||||
selectedCalendars: passedSelectedCalendars.map(getPiiFreeSelectedCalendar),
|
||||
})
|
||||
);
|
||||
const eventBusyDates = await c.getAvailability(dateFrom, dateTo, passedSelectedCalendars);
|
||||
performance.mark("eventBusyDatesEnd");
|
||||
performance.measure(
|
||||
@@ -52,11 +60,14 @@ const getCalendarsEvents = async (
|
||||
"getBusyCalendarTimesStart",
|
||||
"getBusyCalendarTimesEnd"
|
||||
);
|
||||
log.debug({
|
||||
calendarCredentials: calendarCredentials.map(getPiiFreeCredential),
|
||||
selectedCalendars: selectedCalendars.map(getPiiFreeSelectedCalendar),
|
||||
calendarEvents: awaitedResults,
|
||||
});
|
||||
log.debug(
|
||||
"Result",
|
||||
safeStringify({
|
||||
calendarCredentials: calendarCredentials.map(getPiiFreeCredential),
|
||||
selectedCalendars: selectedCalendars.map(getPiiFreeSelectedCalendar),
|
||||
calendarEvents: awaitedResults,
|
||||
})
|
||||
);
|
||||
return awaitedResults;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import { getDailyAppKeys } from "@calcom/app-store/dailyvideo/lib/getDailyAppKey
|
||||
import { sendBrokenIntegrationEmail } from "@calcom/emails";
|
||||
import { getUid } from "@calcom/lib/CalEventParser";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { getPiiFreeCalendarEvent } from "@calcom/lib/piiFreeData";
|
||||
import { getPiiFreeCalendarEvent, getPiiFreeCredential } from "@calcom/lib/piiFreeData";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { GetRecordingsResponseSchema } from "@calcom/prisma/zod-utils";
|
||||
@@ -25,7 +25,7 @@ const getVideoAdapters = async (withCredentials: CredentialPayload[]): Promise<V
|
||||
|
||||
for (const cred of withCredentials) {
|
||||
const appName = cred.type.split("_").join(""); // Transform `zoom_video` to `zoomvideo`;
|
||||
logger.silly("getVideoAdapters", JSON.stringify({ appName, cred }));
|
||||
log.silly("Getting video adapter for", safeStringify({ appName, cred: getPiiFreeCredential(cred) }));
|
||||
const appImportFn = appStore[appName as keyof typeof appStore];
|
||||
|
||||
// Static Link Video Apps don't exist in packages/app-store/index.ts(it's manually maintained at the moment) and they aren't needed there anyway.
|
||||
@@ -55,7 +55,14 @@ const getBusyVideoTimes = async (withCredentials: CredentialPayload[]) =>
|
||||
|
||||
const createMeeting = async (credential: CredentialPayload, calEvent: CalendarEvent) => {
|
||||
const uid: string = getUid(calEvent);
|
||||
log.silly("videoClient:createMeeting", JSON.stringify({ credential, uid, calEvent }));
|
||||
log.silly(
|
||||
"createMeeting",
|
||||
safeStringify({
|
||||
credential: getPiiFreeCredential(credential),
|
||||
uid,
|
||||
calEvent: getPiiFreeCalendarEvent(calEvent),
|
||||
})
|
||||
);
|
||||
if (!credential || !credential.appId) {
|
||||
throw new Error(
|
||||
"Credentials must be set! Video platforms are optional, so this method shouldn't even be called when no video credentials are set."
|
||||
@@ -159,7 +166,10 @@ const updateMeeting = async (
|
||||
const deleteMeeting = async (credential: CredentialPayload | null, uid: string): Promise<unknown> => {
|
||||
if (credential) {
|
||||
const videoAdapter = (await getVideoAdapters([credential]))[0];
|
||||
logger.debug("videoAdapter inside deleteMeeting", { credential, uid });
|
||||
log.debug(
|
||||
"Calling deleteMeeting for",
|
||||
safeStringify({ credential: getPiiFreeCredential(credential), uid })
|
||||
);
|
||||
// There are certain video apps with no video adapter defined. e.g. riverby,whereby
|
||||
if (videoAdapter) {
|
||||
return videoAdapter.deleteMeeting(uid);
|
||||
|
||||
@@ -2,7 +2,6 @@ import type { TFunction } from "next-i18next";
|
||||
|
||||
import { guessEventLocationType } from "@calcom/app-store/locations";
|
||||
import { getVideoCallUrlFromCalEvent } from "@calcom/lib/CalEventParser";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
import { Info } from "./Info";
|
||||
@@ -12,7 +11,6 @@ export function LocationInfo(props: { calEvent: CalendarEvent; t: TFunction }) {
|
||||
|
||||
// We would not be able to determine provider name for DefaultEventLocationTypes
|
||||
const providerName = guessEventLocationType(props.calEvent.location)?.label;
|
||||
logger.debug(`LocationInfo: ${JSON.stringify(props.calEvent)} ${providerName}`);
|
||||
|
||||
const location = props.calEvent.location;
|
||||
let meetingUrl = location?.search(/^https?:/) !== -1 ? location : undefined;
|
||||
|
||||
@@ -147,7 +147,8 @@ describe("handleNewBooking", () => {
|
||||
|
||||
const calendarMock = mockCalendarToHaveNoBusySlots("googlecalendar", {
|
||||
create: {
|
||||
uid: "MOCK_ID",
|
||||
id: "MOCKED_GOOGLE_CALENDAR_EVENT_ID",
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -193,8 +194,8 @@ describe("handleNewBooking", () => {
|
||||
},
|
||||
{
|
||||
type: "google_calendar",
|
||||
uid: "MOCK_ID",
|
||||
meetingId: "MOCK_ID",
|
||||
uid: "MOCKED_GOOGLE_CALENDAR_EVENT_ID",
|
||||
meetingId: "MOCKED_GOOGLE_CALENDAR_EVENT_ID",
|
||||
meetingPassword: "MOCK_PASSWORD",
|
||||
meetingUrl: "https://UNUSED_URL",
|
||||
},
|
||||
@@ -207,7 +208,13 @@ describe("handleNewBooking", () => {
|
||||
videoCallUrl: "http://mock-dailyvideo.example.com/meeting-1",
|
||||
});
|
||||
|
||||
expectSuccessfulBookingCreationEmails({ booker, organizer, emails });
|
||||
expectSuccessfulBookingCreationEmails({
|
||||
booker,
|
||||
organizer,
|
||||
emails,
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
});
|
||||
|
||||
expectBookingCreatedWebhookToHaveBeenFired({
|
||||
booker,
|
||||
organizer,
|
||||
@@ -281,9 +288,12 @@ describe("handleNewBooking", () => {
|
||||
},
|
||||
});
|
||||
|
||||
// Mock a Scenario where iCalUID isn't returned by Google Calendar in which case booking UID is used as the ics UID
|
||||
const calendarMock = mockCalendarToHaveNoBusySlots("googlecalendar", {
|
||||
create: {
|
||||
id: "GOOGLE_CALENDAR_EVENT_ID",
|
||||
uid: "MOCK_ID",
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -329,8 +339,8 @@ describe("handleNewBooking", () => {
|
||||
},
|
||||
{
|
||||
type: "google_calendar",
|
||||
uid: "MOCK_ID",
|
||||
meetingId: "MOCK_ID",
|
||||
uid: "GOOGLE_CALENDAR_EVENT_ID",
|
||||
meetingId: "GOOGLE_CALENDAR_EVENT_ID",
|
||||
meetingPassword: "MOCK_PASSWORD",
|
||||
meetingUrl: "https://UNUSED_URL",
|
||||
},
|
||||
@@ -346,7 +356,12 @@ describe("handleNewBooking", () => {
|
||||
calendarId: null,
|
||||
});
|
||||
|
||||
expectSuccessfulBookingCreationEmails({ booker, organizer, emails });
|
||||
expectSuccessfulBookingCreationEmails({
|
||||
booker,
|
||||
organizer,
|
||||
emails,
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
});
|
||||
expectBookingCreatedWebhookToHaveBeenFired({
|
||||
booker,
|
||||
organizer,
|
||||
@@ -425,6 +440,8 @@ describe("handleNewBooking", () => {
|
||||
const calendarMock = mockCalendarToHaveNoBusySlots("googlecalendar", {
|
||||
create: {
|
||||
uid: "MOCK_ID",
|
||||
id: "GOOGLE_CALENDAR_EVENT_ID",
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -470,8 +487,8 @@ describe("handleNewBooking", () => {
|
||||
},
|
||||
{
|
||||
type: "google_calendar",
|
||||
uid: "MOCK_ID",
|
||||
meetingId: "MOCK_ID",
|
||||
uid: "GOOGLE_CALENDAR_EVENT_ID",
|
||||
meetingId: "GOOGLE_CALENDAR_EVENT_ID",
|
||||
meetingPassword: "MOCK_PASSWORD",
|
||||
meetingUrl: "https://UNUSED_URL",
|
||||
},
|
||||
@@ -484,7 +501,13 @@ describe("handleNewBooking", () => {
|
||||
videoCallUrl: "http://mock-dailyvideo.example.com/meeting-1",
|
||||
});
|
||||
|
||||
expectSuccessfulBookingCreationEmails({ booker, organizer, emails });
|
||||
expectSuccessfulBookingCreationEmails({
|
||||
booker,
|
||||
organizer,
|
||||
emails,
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
});
|
||||
|
||||
expectBookingCreatedWebhookToHaveBeenFired({
|
||||
booker,
|
||||
organizer,
|
||||
@@ -498,7 +521,7 @@ describe("handleNewBooking", () => {
|
||||
|
||||
test(
|
||||
`an error in creating a calendar event should not stop the booking creation - Current behaviour is wrong as the booking is created but no-one is notified of it`,
|
||||
async ({ emails }) => {
|
||||
async ({}) => {
|
||||
const handleNewBooking = (await import("@calcom/features/bookings/lib/handleNewBooking")).default;
|
||||
const booker = getBooker({
|
||||
email: "[email protected]",
|
||||
@@ -546,7 +569,7 @@ describe("handleNewBooking", () => {
|
||||
})
|
||||
);
|
||||
|
||||
const calendarMock = mockCalendarToCrashOnCreateEvent("googlecalendar");
|
||||
const _calendarMock = mockCalendarToCrashOnCreateEvent("googlecalendar");
|
||||
|
||||
const mockBookingData = getMockRequestDataForBooking({
|
||||
data: {
|
||||
@@ -672,9 +695,15 @@ describe("handleNewBooking", () => {
|
||||
},
|
||||
}),
|
||||
});
|
||||
await handleNewBooking(req);
|
||||
const createdBooking = await handleNewBooking(req);
|
||||
|
||||
expectSuccessfulBookingCreationEmails({ booker, organizer, emails });
|
||||
expectSuccessfulBookingCreationEmails({
|
||||
booker,
|
||||
organizer,
|
||||
emails,
|
||||
// Because no calendar was involved, we don't have an ics UID
|
||||
iCalUID: createdBooking.uid,
|
||||
});
|
||||
|
||||
expectBookingCreatedWebhookToHaveBeenFired({
|
||||
booker,
|
||||
@@ -893,95 +922,10 @@ describe("handleNewBooking", () => {
|
||||
})
|
||||
);
|
||||
|
||||
const calendarMock = mockCalendar("googlecalendar", {
|
||||
create: {
|
||||
uid: "MOCK_ID",
|
||||
},
|
||||
busySlots: [
|
||||
{
|
||||
start: `${plus1DateString}T05:00:00.000Z`,
|
||||
end: `${plus1DateString}T05:15:00.000Z`,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const mockBookingData = getMockRequestDataForBooking({
|
||||
data: {
|
||||
start: `${getDate({ dateIncrement: 1 }).dateString}T04:00:00.000Z`,
|
||||
end: `${getDate({ dateIncrement: 1 }).dateString}T05:30:00.000Z`,
|
||||
eventTypeId: 1,
|
||||
responses: {
|
||||
email: booker.email,
|
||||
name: booker.name,
|
||||
location: { optionValue: "", value: "New York" },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const { req } = createMockNextJsRequest({
|
||||
method: "POST",
|
||||
body: mockBookingData,
|
||||
});
|
||||
|
||||
await expect(async () => await handleNewBooking(req)).rejects.toThrowError(
|
||||
"No available users found"
|
||||
);
|
||||
},
|
||||
timeout
|
||||
);
|
||||
|
||||
test(
|
||||
`should fail a booking if there is already a booking in the organizer's selectedCalendars(Single Calendar) with the overlapping time`,
|
||||
async () => {
|
||||
const handleNewBooking = (await import("@calcom/features/bookings/lib/handleNewBooking")).default;
|
||||
const organizerId = 101;
|
||||
const booker = getBooker({
|
||||
email: "[email protected]",
|
||||
name: "Booker",
|
||||
});
|
||||
|
||||
const organizer = getOrganizer({
|
||||
name: "Organizer",
|
||||
email: "[email protected]",
|
||||
id: organizerId,
|
||||
schedules: [TestData.schedules.IstWorkHours],
|
||||
credentials: [getGoogleCalendarCredential()],
|
||||
selectedCalendars: [TestData.selectedCalendars.google],
|
||||
});
|
||||
const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });
|
||||
|
||||
await createBookingScenario(
|
||||
getScenarioData({
|
||||
webhooks: [
|
||||
{
|
||||
userId: organizer.id,
|
||||
eventTriggers: ["BOOKING_CREATED"],
|
||||
subscriberUrl: "http://my-webhook.example.com",
|
||||
active: true,
|
||||
eventTypeId: 1,
|
||||
appId: null,
|
||||
},
|
||||
],
|
||||
eventTypes: [
|
||||
{
|
||||
id: 1,
|
||||
slotInterval: 45,
|
||||
length: 45,
|
||||
users: [
|
||||
{
|
||||
id: 101,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
organizer,
|
||||
apps: [TestData.apps["google-calendar"]],
|
||||
})
|
||||
);
|
||||
|
||||
const calendarMock = mockCalendar("googlecalendar", {
|
||||
const _calendarMock = mockCalendar("googlecalendar", {
|
||||
create: {
|
||||
uid: "MOCK_ID",
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
},
|
||||
busySlots: [
|
||||
{
|
||||
@@ -1075,7 +1019,11 @@ describe("handleNewBooking", () => {
|
||||
metadataLookupKey: "dailyvideo",
|
||||
});
|
||||
|
||||
mockCalendarToHaveNoBusySlots("googlecalendar");
|
||||
mockCalendarToHaveNoBusySlots("googlecalendar", {
|
||||
create: {
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
},
|
||||
});
|
||||
|
||||
const mockBookingData = getMockRequestDataForBooking({
|
||||
data: {
|
||||
@@ -1193,7 +1141,11 @@ describe("handleNewBooking", () => {
|
||||
metadataLookupKey: "dailyvideo",
|
||||
});
|
||||
|
||||
mockCalendarToHaveNoBusySlots("googlecalendar");
|
||||
mockCalendarToHaveNoBusySlots("googlecalendar", {
|
||||
create: {
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
},
|
||||
});
|
||||
|
||||
const mockBookingData = getMockRequestDataForBooking({
|
||||
data: {
|
||||
@@ -1231,7 +1183,12 @@ describe("handleNewBooking", () => {
|
||||
|
||||
expectWorkflowToBeTriggered();
|
||||
|
||||
expectSuccessfulBookingCreationEmails({ booker, organizer, emails });
|
||||
expectSuccessfulBookingCreationEmails({
|
||||
booker,
|
||||
organizer,
|
||||
emails,
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
});
|
||||
|
||||
expectBookingCreatedWebhookToHaveBeenFired({
|
||||
booker,
|
||||
@@ -1306,7 +1263,11 @@ describe("handleNewBooking", () => {
|
||||
metadataLookupKey: "dailyvideo",
|
||||
});
|
||||
|
||||
mockCalendarToHaveNoBusySlots("googlecalendar");
|
||||
mockCalendarToHaveNoBusySlots("googlecalendar", {
|
||||
create: {
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
},
|
||||
});
|
||||
|
||||
const mockBookingData = getMockRequestDataForBooking({
|
||||
data: {
|
||||
@@ -1489,7 +1450,11 @@ describe("handleNewBooking", () => {
|
||||
apps: [TestData.apps["google-calendar"], TestData.apps["daily-video"]],
|
||||
});
|
||||
|
||||
mockCalendarToHaveNoBusySlots("googlecalendar");
|
||||
mockCalendarToHaveNoBusySlots("googlecalendar", {
|
||||
create: {
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
},
|
||||
});
|
||||
await createBookingScenario(scenarioData);
|
||||
|
||||
const createdBooking = await handleNewBooking(req);
|
||||
@@ -1512,7 +1477,12 @@ describe("handleNewBooking", () => {
|
||||
|
||||
expectWorkflowToBeTriggered();
|
||||
|
||||
expectSuccessfulBookingCreationEmails({ booker, organizer, emails });
|
||||
expectSuccessfulBookingCreationEmails({
|
||||
booker,
|
||||
organizer,
|
||||
emails,
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
});
|
||||
expectBookingCreatedWebhookToHaveBeenFired({
|
||||
booker,
|
||||
organizer,
|
||||
@@ -1918,6 +1888,7 @@ describe("handleNewBooking", () => {
|
||||
},
|
||||
update: {
|
||||
uid: "UPDATED_MOCK_ID",
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -2027,7 +1998,12 @@ describe("handleNewBooking", () => {
|
||||
uid: "MOCK_ID",
|
||||
});
|
||||
|
||||
expectSuccessfulBookingRescheduledEmails({ booker, organizer, emails });
|
||||
expectSuccessfulBookingRescheduledEmails({
|
||||
booker,
|
||||
organizer,
|
||||
emails,
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
});
|
||||
expectBookingRescheduledWebhookToHaveBeenFired({
|
||||
booker,
|
||||
organizer,
|
||||
@@ -2132,6 +2108,7 @@ describe("handleNewBooking", () => {
|
||||
uid: "MOCK_ID",
|
||||
},
|
||||
update: {
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
uid: "UPDATED_MOCK_ID",
|
||||
},
|
||||
});
|
||||
@@ -2223,7 +2200,12 @@ describe("handleNewBooking", () => {
|
||||
uid: "MOCK_ID",
|
||||
});
|
||||
|
||||
expectSuccessfulBookingRescheduledEmails({ booker, organizer, emails });
|
||||
expectSuccessfulBookingRescheduledEmails({
|
||||
booker,
|
||||
organizer,
|
||||
emails,
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
});
|
||||
expectBookingRescheduledWebhookToHaveBeenFired({
|
||||
booker,
|
||||
organizer,
|
||||
@@ -2237,7 +2219,7 @@ describe("handleNewBooking", () => {
|
||||
|
||||
test(
|
||||
`an error in updating a calendar event should not stop the rescheduling - Current behaviour is wrong as the booking is resheduled but no-one is notified of it`,
|
||||
async ({ emails }) => {
|
||||
async ({}) => {
|
||||
const handleNewBooking = (await import("@calcom/features/bookings/lib/handleNewBooking")).default;
|
||||
const booker = getBooker({
|
||||
email: "[email protected]",
|
||||
@@ -2315,7 +2297,7 @@ describe("handleNewBooking", () => {
|
||||
})
|
||||
);
|
||||
|
||||
const calendarMock = mockCalendarToCrashOnUpdateEvent("googlecalendar");
|
||||
const _calendarMock = mockCalendarToCrashOnUpdateEvent("googlecalendar");
|
||||
|
||||
const mockBookingData = getMockRequestDataForBooking({
|
||||
data: {
|
||||
|
||||
@@ -35,6 +35,7 @@ import {
|
||||
import { getBookingFieldsWithSystemFields } from "@calcom/features/bookings/lib/getBookingFields";
|
||||
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
|
||||
import { handleWebhookTrigger } from "@calcom/features/bookings/lib/handleWebhookTrigger";
|
||||
import { isEventTypeLoggingEnabled } from "@calcom/features/bookings/lib/isEventTypeLoggingEnabled";
|
||||
import { userOrgQuery } from "@calcom/features/ee/organizations/lib/orgDomains";
|
||||
import {
|
||||
allowDisablingAttendeeConfirmationEmails,
|
||||
@@ -60,6 +61,7 @@ import { HttpError } from "@calcom/lib/http-error";
|
||||
import isOutOfBounds, { BookingDateInPastError } from "@calcom/lib/isOutOfBounds";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { handlePayment } from "@calcom/lib/payment/handlePayment";
|
||||
import { getPiiFreeCalendarEvent, getPiiFreeEventType, getPiiFreeUser } from "@calcom/lib/piiFreeData";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { checkBookingLimits, checkDurationLimits, getLuckyUser } from "@calcom/lib/server";
|
||||
import { getBookerUrl } from "@calcom/lib/server/getBookerUrl";
|
||||
@@ -688,25 +690,14 @@ async function handler(
|
||||
prefix: ["book:user", `${eventTypeId}:${reqBody.user}/${eventTypeSlug}`],
|
||||
});
|
||||
|
||||
if (isLoggingEnabled({ eventTypeId, usernameOrTeamName: reqBody.user })) {
|
||||
if (isEventTypeLoggingEnabled({ eventTypeId, usernameOrTeamName: reqBody.user })) {
|
||||
logger.setSettings({ minLevel: "silly" });
|
||||
}
|
||||
|
||||
loggerWithEventDetails.debug(
|
||||
"handleNewBooking called",
|
||||
JSON.stringify({
|
||||
eventTypeId,
|
||||
eventTypeSlug,
|
||||
startTime: reqBody.start,
|
||||
endTime: reqBody.end,
|
||||
rescheduleUid: reqBody.rescheduleUid,
|
||||
})
|
||||
);
|
||||
|
||||
const fullName = getFullName(bookerName);
|
||||
|
||||
const tGuests = await getTranslation("en", "common");
|
||||
loggerWithEventDetails.debug(`Booking eventType ${eventTypeId} started`);
|
||||
|
||||
const dynamicUserList = Array.isArray(reqBody.user) ? reqBody.user : getUsernameList(reqBody.user);
|
||||
if (!eventType) throw new HttpError({ statusCode: 404, message: "eventType.notFound" });
|
||||
|
||||
@@ -714,6 +705,30 @@ async function handler(
|
||||
!!eventType.schedulingType && ["COLLECTIVE", "ROUND_ROBIN"].includes(eventType.schedulingType);
|
||||
|
||||
const paymentAppData = getPaymentAppData(eventType);
|
||||
loggerWithEventDetails.debug(
|
||||
`Booking eventType ${eventTypeId} started`,
|
||||
safeStringify({
|
||||
reqBody: {
|
||||
user: reqBody.user,
|
||||
eventTypeId,
|
||||
eventTypeSlug,
|
||||
startTime: reqBody.start,
|
||||
endTime: reqBody.end,
|
||||
rescheduleUid: reqBody.rescheduleUid,
|
||||
location: location,
|
||||
},
|
||||
isTeamEventType,
|
||||
eventType: getPiiFreeEventType(eventType),
|
||||
dynamicUserList,
|
||||
paymentAppData: {
|
||||
enabled: paymentAppData.enabled,
|
||||
price: paymentAppData.price,
|
||||
paymentOption: paymentAppData.paymentOption,
|
||||
currency: paymentAppData.currency,
|
||||
appId: paymentAppData.appId,
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
let timeOutOfBounds = false;
|
||||
try {
|
||||
@@ -837,6 +852,13 @@ async function handler(
|
||||
: user.isFixed || eventType.schedulingType !== SchedulingType.ROUND_ROBIN,
|
||||
}));
|
||||
|
||||
loggerWithEventDetails.debug(
|
||||
"Concerned users",
|
||||
safeStringify({
|
||||
users: users.map(getPiiFreeUser),
|
||||
})
|
||||
);
|
||||
|
||||
let locationBodyString = location;
|
||||
|
||||
// TODO: It's definition should be moved to getLocationValueForDb
|
||||
@@ -921,6 +943,13 @@ async function handler(
|
||||
|
||||
const luckyUsers: typeof users = [];
|
||||
const luckyUserPool = availableUsers.filter((user) => !user.isFixed);
|
||||
loggerWithEventDetails.debug(
|
||||
"Computed available users",
|
||||
safeStringify({
|
||||
availableUsers: availableUsers.map((user) => user.id),
|
||||
luckyUserPool: luckyUserPool.map((user) => user.id),
|
||||
})
|
||||
);
|
||||
// loop through all non-fixed hosts and get the lucky users
|
||||
while (luckyUserPool.length > 0 && luckyUsers.length < 1 /* TODO: Add variable */) {
|
||||
const newLuckyUser = await getLuckyUser("MAXIMIZE_AVAILABILITY", {
|
||||
@@ -946,6 +975,7 @@ async function handler(
|
||||
}
|
||||
|
||||
const [organizerUser] = users;
|
||||
|
||||
const tOrganizer = await getTranslation(organizerUser?.locale ?? "en", "common");
|
||||
|
||||
const allCredentials = await getAllCredentials(organizerUser, eventType);
|
||||
@@ -1988,6 +2018,17 @@ async function handler(
|
||||
|
||||
type Booking = Prisma.PromiseReturnType<typeof createBooking>;
|
||||
let booking: (Booking & { appsStatus?: AppsStatus[] }) | null = null;
|
||||
loggerWithEventDetails.debug(
|
||||
"Going to create booking in DB now",
|
||||
safeStringify({
|
||||
organizerUser: organizerUser.id,
|
||||
attendeesList: attendeesList.map((guest) => ({ timeZone: guest.timeZone })),
|
||||
requiresConfirmation,
|
||||
isConfirmedByDefault,
|
||||
userReschedulingIsOwner,
|
||||
})
|
||||
);
|
||||
|
||||
try {
|
||||
booking = await createBooking();
|
||||
|
||||
@@ -2177,7 +2218,7 @@ async function handler(
|
||||
};
|
||||
|
||||
loggerWithEventDetails.error(
|
||||
`Booking ${organizerUser.username} failed`,
|
||||
`Failure in creating events in some of the integrations ${organizerUser.username} failed`,
|
||||
safeStringify({ error, results })
|
||||
);
|
||||
} else {
|
||||
@@ -2201,6 +2242,7 @@ async function handler(
|
||||
const googleCalResult = results[googleCalIndex];
|
||||
|
||||
if (!googleCalResult) {
|
||||
loggerWithEventDetails.warn("Google Calendar not installed but using Google Meet as location");
|
||||
results.push({
|
||||
...googleMeetResult,
|
||||
success: false,
|
||||
@@ -2263,6 +2305,12 @@ async function handler(
|
||||
}
|
||||
}
|
||||
|
||||
loggerWithEventDetails.debug(
|
||||
"Sending scheduled emails for booking confirmation",
|
||||
safeStringify({
|
||||
calEvent: getPiiFreeCalendarEvent(evt),
|
||||
})
|
||||
);
|
||||
await sendScheduledEmails(
|
||||
{
|
||||
...evt,
|
||||
@@ -2285,9 +2333,16 @@ async function handler(
|
||||
!!booking;
|
||||
|
||||
if (!isConfirmedByDefault && noEmail !== true && !bookingRequiresPayment) {
|
||||
loggerWithEventDetails.debug(
|
||||
`Booking ${organizerUser.username} requires confirmation, sending request emails`,
|
||||
safeStringify({
|
||||
calEvent: getPiiFreeCalendarEvent(evt),
|
||||
})
|
||||
);
|
||||
await sendOrganizerRequestEmail({ ...evt, additionalNotes });
|
||||
await sendAttendeeRequestEmail({ ...evt, additionalNotes }, attendeesList[0]);
|
||||
}
|
||||
|
||||
const metadata = videoCallUrl
|
||||
? {
|
||||
videoCallUrl: getVideoCallUrlFromCalEvent(evt),
|
||||
@@ -2311,6 +2366,7 @@ async function handler(
|
||||
};
|
||||
|
||||
if (bookingRequiresPayment) {
|
||||
loggerWithEventDetails.debug(`Booking ${organizerUser.username} requires payment`);
|
||||
// Load credentials.app.categories
|
||||
const credentialPaymentAppCategories = await prisma.credential.findMany({
|
||||
where: {
|
||||
@@ -2555,31 +2611,3 @@ const findBookingQuery = async (bookingId: number) => {
|
||||
// Don't leak any sensitive data
|
||||
return foundBooking;
|
||||
};
|
||||
|
||||
function isLoggingEnabled({
|
||||
eventTypeId,
|
||||
usernameOrTeamName,
|
||||
}: {
|
||||
eventTypeId?: number | null;
|
||||
usernameOrTeamName?: string | string[];
|
||||
}) {
|
||||
const usernameOrTeamnamesList =
|
||||
usernameOrTeamName instanceof Array ? usernameOrTeamName : [usernameOrTeamName];
|
||||
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
||||
const bookingLoggingEventIds = process.env.BOOKING_LOGGING_EVENT_IDS || "";
|
||||
const isEnabled = bookingLoggingEventIds.split(",").some((id) => {
|
||||
if (Number(id.trim()) === eventTypeId) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (isEnabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
||||
const bookingLoggingUsername = process.env.BOOKING_LOGGING_USER_OR_TEAM_NAME || "";
|
||||
return bookingLoggingUsername.split(",").some((u) => {
|
||||
return usernameOrTeamnamesList.some((foundUsername) => foundUsername === u.trim());
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
export function isEventTypeLoggingEnabled({
|
||||
eventTypeId,
|
||||
usernameOrTeamName,
|
||||
}: {
|
||||
eventTypeId?: number | null;
|
||||
usernameOrTeamName?: string | string[];
|
||||
}) {
|
||||
const usernameOrTeamnamesList =
|
||||
usernameOrTeamName instanceof Array ? usernameOrTeamName : [usernameOrTeamName];
|
||||
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
||||
const bookingLoggingEventIds = process.env.BOOKING_LOGGING_EVENT_IDS || "";
|
||||
const isEnabled = bookingLoggingEventIds.split(",").some((id) => {
|
||||
if (Number(id.trim()) === eventTypeId) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (isEnabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
||||
const bookingLoggingUsername = process.env.BOOKING_LOGGING_USER_OR_TEAM_NAME || "";
|
||||
return bookingLoggingUsername.split(",").some((u) => {
|
||||
return usernameOrTeamnamesList.some((foundUsername) => foundUsername === u.trim());
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { Credential, SelectedCalendar } from "@prisma/client";
|
||||
import type { Credential, SelectedCalendar, DestinationCalendar } from "@prisma/client";
|
||||
|
||||
import type { EventType } from "@calcom/prisma/client";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
export function getPiiFreeCalendarEvent(calEvent: CalendarEvent) {
|
||||
@@ -15,6 +16,7 @@ export function getPiiFreeCalendarEvent(calEvent: CalendarEvent) {
|
||||
recurrence: calEvent.recurrence,
|
||||
requiresConfirmation: calEvent.requiresConfirmation,
|
||||
uid: calEvent.uid,
|
||||
iCalUID: calEvent.iCalUID,
|
||||
/**
|
||||
* Let's just get a boolean value for PII sensitive fields so that we atleast know if it's present or not
|
||||
*/
|
||||
@@ -66,10 +68,54 @@ export function getPiiFreeSelectedCalendar(selectedCalendar: Partial<SelectedCal
|
||||
return {
|
||||
integration: selectedCalendar.integration,
|
||||
userId: selectedCalendar.userId,
|
||||
/**
|
||||
* Let's just get a boolean value for PII sensitive fields so that we atleast know if it's present or not
|
||||
*/
|
||||
externalId: !!selectedCalendar.externalId,
|
||||
// Get first 3 characters of externalId, so that we know what it could be but not the full value
|
||||
externalId: selectedCalendar.externalId?.slice(0, 3),
|
||||
credentialId: !!selectedCalendar.credentialId,
|
||||
};
|
||||
}
|
||||
|
||||
export function getPiiFreeDestinationCalendar(destinationCalendar: Partial<DestinationCalendar>) {
|
||||
return {
|
||||
integration: destinationCalendar.integration,
|
||||
userId: destinationCalendar.userId,
|
||||
/**
|
||||
* Let's just get a boolean value for PII sensitive fields so that we atleast know if it's present or not
|
||||
*/
|
||||
externalId: !!destinationCalendar.externalId,
|
||||
credentialId: !!destinationCalendar.credentialId,
|
||||
};
|
||||
}
|
||||
|
||||
export function getPiiFreeEventType(eventType: Partial<Omit<EventType, "recurringEvent">>) {
|
||||
return {
|
||||
id: eventType.id,
|
||||
schedulingType: eventType.schedulingType,
|
||||
seatsPerTimeSlot: eventType.seatsPerTimeSlot,
|
||||
};
|
||||
}
|
||||
|
||||
export function getPiiFreeUser(user: {
|
||||
id?: number;
|
||||
username?: string | null;
|
||||
isFixed?: boolean;
|
||||
timeZone?: string;
|
||||
allowDynamicBooking?: boolean | null;
|
||||
defaultScheduleId?: number | null;
|
||||
organizationId?: number | null;
|
||||
credentials?: Credential[];
|
||||
destinationCalendar?: DestinationCalendar | null;
|
||||
}) {
|
||||
return {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
isFixed: user.isFixed,
|
||||
timeZone: user.timeZone,
|
||||
allowDynamicBooking: user.allowDynamicBooking,
|
||||
defaultScheduleId: user.defaultScheduleId,
|
||||
organizationId: user.organizationId,
|
||||
credentials: user.credentials?.map(getPiiFreeCredential),
|
||||
destinationCalendar: user.destinationCalendar
|
||||
? getPiiFreeDestinationCalendar(user.destinationCalendar)
|
||||
: user.destinationCalendar,
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import logger from "@calcom/lib/logger";
|
||||
import type { MembershipRole } from "@calcom/prisma/enums";
|
||||
|
||||
import { safeStringify } from "../safeStringify";
|
||||
import type { ConsoleUserInfoType, TeamInfoType, WebUserInfoType } from "./ISyncService";
|
||||
import services from "./services";
|
||||
import CloseComService from "./services/CloseComService";
|
||||
@@ -9,7 +10,7 @@ const log = logger.getChildLogger({ prefix: [`[[SyncServiceManager] `] });
|
||||
|
||||
export const createConsoleUser = async (user: ConsoleUserInfoType | null | undefined) => {
|
||||
if (user) {
|
||||
log.debug("createConsoleUser", { user });
|
||||
log.debug("createConsoleUser", safeStringify({ user }));
|
||||
try {
|
||||
Promise.all(
|
||||
services.map(async (serviceClass) => {
|
||||
@@ -24,16 +25,16 @@ export const createConsoleUser = async (user: ConsoleUserInfoType | null | undef
|
||||
})
|
||||
);
|
||||
} catch (e) {
|
||||
log.warn("createConsoleUser", e);
|
||||
log.warn("createConsoleUser", safeStringify({ error: e }));
|
||||
}
|
||||
} else {
|
||||
log.warn("createConsoleUser:noUser", { user });
|
||||
log.warn("createConsoleUser:noUser", safeStringify({ user }));
|
||||
}
|
||||
};
|
||||
|
||||
export const createWebUser = async (user: WebUserInfoType | null | undefined) => {
|
||||
if (user) {
|
||||
log.debug("createWebUser", { user });
|
||||
log.debug("createWebUser", safeStringify({ user }));
|
||||
try {
|
||||
Promise.all(
|
||||
services.map(async (serviceClass) => {
|
||||
@@ -48,16 +49,16 @@ export const createWebUser = async (user: WebUserInfoType | null | undefined) =>
|
||||
})
|
||||
);
|
||||
} catch (e) {
|
||||
log.warn("createWebUser", e);
|
||||
log.warn("createWebUser", safeStringify({ error: e }));
|
||||
}
|
||||
} else {
|
||||
log.warn("createWebUser:noUser", { user });
|
||||
log.warn("createWebUser:noUser", safeStringify({ user }));
|
||||
}
|
||||
};
|
||||
|
||||
export const updateWebUser = async (user: WebUserInfoType | null | undefined) => {
|
||||
if (user) {
|
||||
log.debug("updateWebUser", { user });
|
||||
log.debug("updateWebUser", safeStringify({ user }));
|
||||
try {
|
||||
Promise.all(
|
||||
services.map(async (serviceClass) => {
|
||||
@@ -72,10 +73,10 @@ export const updateWebUser = async (user: WebUserInfoType | null | undefined) =>
|
||||
})
|
||||
);
|
||||
} catch (e) {
|
||||
log.warn("updateWebUser", e);
|
||||
log.warn("updateWebUser", safeStringify({ error: e }));
|
||||
}
|
||||
} else {
|
||||
log.warn("updateWebUser:noUser", { user });
|
||||
log.warn("updateWebUser:noUser", safeStringify({ user }));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
declare global {
|
||||
// eslint-disable-next-line no-var
|
||||
var testEmails: {
|
||||
icalEvent?: {
|
||||
filename: string;
|
||||
content: string;
|
||||
};
|
||||
to: string;
|
||||
from: string;
|
||||
subject: string;
|
||||
|
||||
@@ -8,6 +8,7 @@ import { getUserAvailability } from "@calcom/core/getUserAvailability";
|
||||
import type { Dayjs } from "@calcom/dayjs";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { getSlugOrRequestedSlug, orgDomainConfig } from "@calcom/ee/organizations/lib/orgDomains";
|
||||
import { isEventTypeLoggingEnabled } from "@calcom/features/bookings/lib/isEventTypeLoggingEnabled";
|
||||
import { getDefaultEvent } from "@calcom/lib/defaultEvents";
|
||||
import isTimeOutOfBounds from "@calcom/lib/isOutOfBounds";
|
||||
import logger from "@calcom/lib/logger";
|
||||
@@ -266,25 +267,30 @@ export function getRegularOrDynamicEventType(
|
||||
|
||||
export async function getAvailableSlots({ input, ctx }: GetScheduleOptions) {
|
||||
const orgDetails = orgDomainConfig(ctx?.req?.headers.host ?? "");
|
||||
|
||||
if (input.debug === true) {
|
||||
logger.setSettings({ minLevel: "debug" });
|
||||
}
|
||||
if (process.env.INTEGRATION_TEST_MODE === "true") {
|
||||
logger.setSettings({ minLevel: "silly" });
|
||||
}
|
||||
const startPrismaEventTypeGet = performance.now();
|
||||
const eventType = await getRegularOrDynamicEventType(input, orgDetails);
|
||||
const endPrismaEventTypeGet = performance.now();
|
||||
logger.debug(
|
||||
`Prisma eventType get took ${endPrismaEventTypeGet - startPrismaEventTypeGet}ms for event:${
|
||||
input.eventTypeId
|
||||
}`
|
||||
);
|
||||
|
||||
if (!eventType) {
|
||||
throw new TRPCError({ code: "NOT_FOUND" });
|
||||
}
|
||||
|
||||
if (isEventTypeLoggingEnabled({ eventTypeId: eventType.id })) {
|
||||
logger.setSettings({ minLevel: "debug" });
|
||||
}
|
||||
|
||||
const loggerWithEventDetails = logger.getChildLogger({
|
||||
prefix: ["getAvailableSlots", `${eventType.id}:${input.usernameList}/${input.eventTypeSlug}`],
|
||||
});
|
||||
|
||||
loggerWithEventDetails.debug(
|
||||
`Prisma eventType get took ${endPrismaEventTypeGet - startPrismaEventTypeGet}ms for event:${
|
||||
input.eventTypeId
|
||||
}`
|
||||
);
|
||||
const getStartTime = (startTimeInput: string, timeZone?: string) => {
|
||||
const startTimeMin = dayjs.utc().add(eventType.minimumBookingNotice, "minutes");
|
||||
const startTime = timeZone === "Etc/GMT" ? dayjs.utc(startTimeInput) : dayjs(startTimeInput).tz(timeZone);
|
||||
@@ -598,12 +604,12 @@ export async function getAvailableSlots({ input, ctx }: GetScheduleOptions) {
|
||||
Object.create(null)
|
||||
);
|
||||
|
||||
logger.debug(`getSlots took ${getSlotsTime}ms and executed ${getSlotsCount} times`);
|
||||
loggerWithEventDetails.debug(`getSlots took ${getSlotsTime}ms and executed ${getSlotsCount} times`);
|
||||
|
||||
logger.debug(
|
||||
loggerWithEventDetails.debug(
|
||||
`checkForAvailability took ${checkForAvailabilityTime}ms and executed ${checkForAvailabilityCount} times`
|
||||
);
|
||||
logger.silly(`Available slots: ${JSON.stringify(computedAvailableSlots)}`);
|
||||
loggerWithEventDetails.debug(`Available slots: ${JSON.stringify(computedAvailableSlots)}`);
|
||||
|
||||
return {
|
||||
slots: computedAvailableSlots,
|
||||
|
||||
Reference in new issue
Block a user