feat: Enable Conferencing Apps for Team Events [CAL-1925] (#10383)

Co-authored-by: Omar López <[email protected]>
Co-authored-by: Hariom Balhara <[email protected]>
This commit is contained in:
authored and GitHub committed 2023-08-02 09:24:28 +05:30
1 parent a9344115d2
commit 617e665004
30 files changed
+310 -140

No files matched your search

@@ -1,8 +1,5 @@
import { getLocationGroupedOptions } from "@calcom/app-store/utils";
import getEnabledApps from "@calcom/lib/apps/getEnabledApps";
import { getLocationGroupedOptions } from "@calcom/app-store/server";
import { getTranslation } from "@calcom/lib/server/i18n";
import { prisma } from "@calcom/prisma";
import { AppCategories } from "@calcom/prisma/enums";
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
import type { TLocationOptionsInputSchema } from "./locationOptions.schema";
@@ -15,31 +12,11 @@ type LocationOptionsOptions = {
};
export const locationOptionsHandler = async ({ ctx, input }: LocationOptionsOptions) => {
const credentials = await prisma.credential.findMany({
where: {
userId: ctx.user.id,
app: {
categories: {
hasSome: [AppCategories.conferencing, AppCategories.video],
},
},
},
select: {
id: true,
type: true,
key: true,
userId: true,
teamId: true,
appId: true,
invalid: true,
},
});
const integrations = await getEnabledApps(credentials, true);
const { teamId } = input;
const t = await getTranslation(ctx.user.locale ?? "en", "common");
const locationOptions = getLocationGroupedOptions(integrations, t);
const locationOptions = await getLocationGroupedOptions(teamId ? { teamId } : { userId: ctx.user.id }, t);
// If it is a team event then move the "use host location" option to top
if (input.teamId) {
const conferencingIndex = locationOptions.findIndex((option) => option.label === "Conferencing");
@@ -6,6 +6,7 @@ import logger from "@calcom/lib/logger";
import { getTranslation } from "@calcom/lib/server";
import { prisma } from "@calcom/prisma";
import type { AdditionalInformation, CalendarEvent } from "@calcom/types/Calendar";
import type { CredentialPayload } from "@calcom/types/Credential";
import { TRPCError } from "@trpc/server";
@@ -21,7 +22,7 @@ type EditLocationOptions = {
};
export const editLocationHandler = async ({ ctx, input }: EditLocationOptions) => {
const { bookingId, newLocation: location } = input;
const { bookingId, newLocation: location, details } = input;
const { booking } = ctx;
try {
@@ -37,6 +38,16 @@ export const editLocationHandler = async ({ ctx, input }: EditLocationOptions) =
},
});
let conferenceCredential: CredentialPayload | null = null;
if (details?.credentialId) {
conferenceCredential = await prisma.credential.findFirst({
where: {
id: details.credentialId,
},
});
}
const tOrganizer = await getTranslation(organizer.locale ?? "en", "common");
const attendeesListPromises = booking.attendees.map(async (attendee) => {
@@ -69,12 +80,19 @@ export const editLocationHandler = async ({ ctx, input }: EditLocationOptions) =
uid: booking.uid,
recurringEvent: parseRecurringEvent(booking.eventType?.recurringEvent),
location,
conferenceCredentialId: details?.credentialId,
destinationCalendar: booking?.destinationCalendar || booking?.user?.destinationCalendar,
seatsPerTimeSlot: booking.eventType?.seatsPerTimeSlot,
seatsShowAttendees: booking.eventType?.seatsShowAttendees,
};
const eventManager = new EventManager(ctx.user);
const eventManager = new EventManager({
...ctx.user,
credentials: [
...(ctx.user.credentials ? ctx.user.credentials : []),
...(conferenceCredential ? [conferenceCredential] : []),
],
});
const updatedResult = await eventManager.updateLocation(evt, booking);
const results = updatedResult.results;
@@ -6,6 +6,7 @@ import { commonBookingSchema } from "./types";
export const ZEditLocationInputSchema = commonBookingSchema.extend({
newLocation: z.string().transform((val) => val || DailyLocationType),
details: z.object({ credentialId: z.number().optional() }).optional(),
});
export type TEditLocationInputSchema = z.infer<typeof ZEditLocationInputSchema>;
@@ -179,6 +179,7 @@ export const getHandler = async ({ ctx, input }: GetOptions) => {
seatsShowAttendees: true,
team: {
select: {
id: true,
name: true,
},
},