Files
calendar/packages/features/bookings/lib/handleNewBooking/getVideoCallDetails.ts
T
b4f1b5aebe refactor: handleNewBooking #4 (#15673)
* refactor: handleNewBooking #3

* refactor: create booking factor

* refactor: handleNewBooking

* refactor: seats and rescheduleUId

* chore: remove comment

* fix: type err

* chore: add missing statement

* chore: use less params and other improvements

* chore: name

* chore: improvement

* fix: type err

* Typo fix

* chore: fix type err

* refactor: more readable

* refactor: improve code

* fix: conflicts

---------

Co-authored-by: Joe Au-Yeung <j.auyeung419@gmail.com>
Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com>
2024-10-02 10:26:25 -04:00

33 lines
1.2 KiB
TypeScript

import type { AdditionalInformation } from "@calcom/types/Calendar";
import type { EventResult } from "@calcom/types/EventManager";
type ExtraAdditionalInfo = AdditionalInformation & {
url?: string | undefined;
iCalUID?: string | undefined;
};
type VideoResult = EventResult<ExtraAdditionalInfo>;
function extractUpdatedVideoEvent(result: VideoResult | undefined): ExtraAdditionalInfo | undefined {
if (!result || !result.success) return undefined;
return Array.isArray(result.updatedEvent) ? result.updatedEvent[0] : result.updatedEvent;
}
function extractMetadata(event: ExtraAdditionalInfo): AdditionalInformation {
return {
hangoutLink: event.hangoutLink,
conferenceData: event.conferenceData,
entryPoints: event.entryPoints,
};
}
export function getVideoCallDetails({ results }: { results: VideoResult[] }) {
const firstVideoResult = results.find((result) => result.type.includes("_video"));
const updatedVideoEvent = extractUpdatedVideoEvent(firstVideoResult);
const metadata = updatedVideoEvent ? extractMetadata(updatedVideoEvent) : {};
const videoCallUrl = metadata.hangoutLink || updatedVideoEvent?.url;
return { videoCallUrl, metadata, updatedVideoEvent };
}