From 66c1e29d919cc09f24bb9238e47ee1452d5d72f1 Mon Sep 17 00:00:00 2001 From: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Date: Thu, 20 Jul 2023 12:57:10 -0400 Subject: [PATCH] fix: Default to Daily if Viable (#10279) * Default to daily if viable * Add Zod schema parsing --- .../playwright/manage-booking-questions.e2e.ts | 2 -- packages/core/EventManager.ts | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/apps/web/playwright/manage-booking-questions.e2e.ts b/apps/web/playwright/manage-booking-questions.e2e.ts index 7685b91661..b05a321fb5 100644 --- a/apps/web/playwright/manage-booking-questions.e2e.ts +++ b/apps/web/playwright/manage-booking-questions.e2e.ts @@ -297,8 +297,6 @@ async function runTestStepsCommonForTeamAndUserEventType( }, }); - expect(payload.location).toBe("integrations:daily"); - expect(payload.attendees[0]).toMatchObject({ name: "Booker", email: "booker@example.com", diff --git a/packages/core/EventManager.ts b/packages/core/EventManager.ts index 95f1d9951a..47b8c0114b 100644 --- a/packages/core/EventManager.ts +++ b/packages/core/EventManager.ts @@ -5,6 +5,7 @@ import type { z } from "zod"; import { getCalendar } from "@calcom/app-store/_utils/getCalendar"; import { FAKE_DAILY_CREDENTIAL } from "@calcom/app-store/dailyvideo/lib/VideoApiAdapter"; +import { appKeysSchema as calVideoKeysSchema } from "@calcom/app-store/dailyvideo/zod"; import { getEventLocationTypeFromApp } from "@calcom/app-store/locations"; import { MeetLocationType } from "@calcom/app-store/locations"; import getApps from "@calcom/app-store/utils"; @@ -94,7 +95,22 @@ export default class EventManager { public async create(event: CalendarEvent): Promise { const evt = processLocation(event); // Fallback to cal video if no location is set - if (!evt.location) evt["location"] = "integrations:daily"; + if (!evt.location) { + // See if cal video is enabled & has keys + const calVideo = await prisma.app.findFirst({ + where: { + slug: "daily-video", + }, + select: { + keys: true, + enabled: true, + }, + }); + + const calVideoKeys = calVideoKeysSchema.safeParse(calVideo?.keys); + + if (calVideo?.enabled && calVideoKeys.success) evt["location"] = "integrations:daily"; + } // Fallback to Cal Video if Google Meet is selected w/o a Google Cal if (evt.location === MeetLocationType && evt.destinationCalendar?.integration !== "google_calendar") {