* added api/v2 for zoom connect * Update conferencing.controller.ts * fix: added api for ConferencingAppsViewPlatformWrapper * type fixes * added getBulkEventTypes api for bulk-update default location * added bulk-update-to-default-location * fix:bulk-update-to-default-location * invalidated * fixed returnTo and onErrorReturnTo * make logos work for conferencing atoms * smalll improvements * fixup * share common types * type fix, and fixed a typo * fix: type-error * fix: json.parse(json.parse()) * fix: invalidate query * fix: removing app throws error in the main app * undo platform-libraries-1.2.3 * update platform-libraries version --------- Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import type { LocationObject } from "@calcom/app-store/locations";
|
|
import { getAppFromSlug } from "@calcom/app-store/utils";
|
|
import type { PrismaClient } from "@calcom/prisma";
|
|
import type { User } from "@calcom/prisma/client";
|
|
import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";
|
|
|
|
import { TRPCError } from "@trpc/server";
|
|
|
|
export const bulkUpdateEventsToDefaultLocation = async ({
|
|
eventTypeIds,
|
|
user,
|
|
prisma,
|
|
}: {
|
|
eventTypeIds: number[];
|
|
user: Pick<User, "id" | "metadata">;
|
|
prisma: PrismaClient;
|
|
}) => {
|
|
const defaultApp = userMetadataSchema.parse(user.metadata)?.defaultConferencingApp;
|
|
|
|
if (!defaultApp) {
|
|
throw new TRPCError({
|
|
code: "BAD_REQUEST",
|
|
message: "Default conferencing app not set",
|
|
});
|
|
}
|
|
|
|
const foundApp = getAppFromSlug(defaultApp.appSlug);
|
|
const appType = foundApp?.appData?.location?.type;
|
|
if (!appType) {
|
|
throw new TRPCError({
|
|
code: "BAD_REQUEST",
|
|
message: `Default conferencing app '${defaultApp.appSlug}' doesnt exist.`,
|
|
});
|
|
}
|
|
|
|
const credential = await prisma.credential.findFirst({
|
|
where: {
|
|
userId: user.id,
|
|
appId: foundApp.slug,
|
|
},
|
|
select: {
|
|
id: true,
|
|
},
|
|
});
|
|
|
|
return await prisma.eventType.updateMany({
|
|
where: {
|
|
id: {
|
|
in: eventTypeIds,
|
|
},
|
|
userId: user.id,
|
|
},
|
|
data: {
|
|
locations: [
|
|
{ type: appType, link: defaultApp.appLink, credentialId: credential?.id },
|
|
] as LocationObject[],
|
|
},
|
|
});
|
|
};
|