From e04cb8fc618b9f47b2bb7466b979d2f21bdef88b Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Fri, 22 Jul 2022 17:22:17 +0530 Subject: [PATCH] Riverside,whereby doesnt have videoApi handle that (#3494) --- packages/core/videoClient.ts | 16 ++++++++++------ packages/types/VideoApiAdapter.d.ts | 15 +++++++++------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/core/videoClient.ts b/packages/core/videoClient.ts index d2102c6f20..af5e5ebc9f 100644 --- a/packages/core/videoClient.ts +++ b/packages/core/videoClient.ts @@ -6,7 +6,7 @@ import appStore from "@calcom/app-store"; import { sendBrokenIntegrationEmail } from "@calcom/emails"; import { getUid } from "@calcom/lib/CalEventParser"; import logger from "@calcom/lib/logger"; -import type { CalendarEvent } from "@calcom/types/Calendar"; +import type { CalendarEvent, EventBusyDate } from "@calcom/types/Calendar"; import type { EventResult, PartialReference } from "@calcom/types/EventManager"; import type { VideoApiAdapter, VideoApiAdapterFactory, VideoCallData } from "@calcom/types/VideoApiAdapter"; @@ -29,8 +29,8 @@ const getVideoAdapters = (withCredentials: Credential[]): VideoApiAdapter[] => }, []); const getBusyVideoTimes = (withCredentials: Credential[]) => - Promise.all(getVideoAdapters(withCredentials).map((c) => c.getAvailability())).then((results) => - results.reduce((acc, availability) => acc.concat(availability), []) + Promise.all(getVideoAdapters(withCredentials).map((c) => c?.getAvailability())).then((results) => + results.reduce((acc, availability) => acc.concat(availability), [] as (EventBusyDate | undefined)[]) ); const createMeeting = async (credential: Credential, calEvent: CalendarEvent) => { @@ -44,7 +44,7 @@ const createMeeting = async (credential: Credential, calEvent: CalendarEvent) => const videoAdapters = getVideoAdapters([credential]); const [firstVideoAdapter] = videoAdapters; - const createdMeeting = await firstVideoAdapter.createMeeting(calEvent).catch(async (e) => { + const createdMeeting = await firstVideoAdapter?.createMeeting(calEvent).catch(async (e) => { await sendBrokenIntegrationEmail(calEvent, "video"); console.error("createMeeting failed", e, calEvent); }); @@ -79,7 +79,7 @@ const updateMeeting = async ( const [firstVideoAdapter] = getVideoAdapters([credential]); const updatedMeeting = credential && bookingRef - ? await firstVideoAdapter.updateMeeting(bookingRef, calEvent).catch(async (e) => { + ? await firstVideoAdapter?.updateMeeting(bookingRef, calEvent).catch(async (e) => { await sendBrokenIntegrationEmail(calEvent, "video"); log.error("updateMeeting failed", e, calEvent); success = false; @@ -107,7 +107,11 @@ const updateMeeting = async ( const deleteMeeting = (credential: Credential, uid: string): Promise => { if (credential) { - return getVideoAdapters([credential])[0].deleteMeeting(uid); + const videoAdapter = getVideoAdapters([credential])[0]; + // There are certain video apps with no video adapter defined. e.g. riverby,whereby + if (videoAdapter) { + return videoAdapter.deleteMeeting(uid); + } } return Promise.resolve({}); diff --git a/packages/types/VideoApiAdapter.d.ts b/packages/types/VideoApiAdapter.d.ts index df76145d3a..81e21c5e23 100644 --- a/packages/types/VideoApiAdapter.d.ts +++ b/packages/types/VideoApiAdapter.d.ts @@ -9,14 +9,17 @@ export interface VideoCallData { url: string; } -export interface VideoApiAdapter { - createMeeting(event: CalendarEvent): Promise; +// VideoApiAdapter is defined by the Video App. The App currently can choose to not define it. So, consider in type that VideoApiAdapter can be undefined. +export type VideoApiAdapter = + | { + createMeeting(event: CalendarEvent): Promise; - updateMeeting(bookingRef: PartialReference, event: CalendarEvent): Promise; + updateMeeting(bookingRef: PartialReference, event: CalendarEvent): Promise; - deleteMeeting(uid: string): Promise; + deleteMeeting(uid: string): Promise; - getAvailability(dateFrom?: string, dateTo?: string): Promise; -} + getAvailability(dateFrom?: string, dateTo?: string): Promise; + } + | undefined; export type VideoApiAdapterFactory = (credential: Credential) => VideoApiAdapter;