fix: Default to Daily if Viable (#10279)

* Default to daily if viable

* Add Zod schema parsing
pull/10186/head^2
Joe Au-Yeung 2023-07-20 12:57:10 -04:00 committed by GitHub
parent 3c57082fa6
commit 66c1e29d91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -297,8 +297,6 @@ async function runTestStepsCommonForTeamAndUserEventType(
},
});
expect(payload.location).toBe("integrations:daily");
expect(payload.attendees[0]).toMatchObject({
name: "Booker",
email: "booker@example.com",

View File

@ -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<CreateUpdateResult> {
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") {