Files
calendar/packages/app-store/_utils/bulkUpdateEventsToDefaultLocation.ts
T
Benny JooandGitHub 9156848503 refactor: circular deps between app store and lib [2] (#23734)
* mv getDefaultLocations

* fix

* 2 more utils

* update imports

* fix

* move getConnectedApps

* move handlePaymentSuccess

* update imports

* fix import

* publish platform libraries
2025-09-10 23:18:59 -03:00

53 lines
1.3 KiB
TypeScript

import type { PrismaClient } from "@calcom/prisma";
import type { User } from "@calcom/prisma/client";
import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";
import type { LocationObject } from "../locations";
import { getAppFromSlug } from "../utils";
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 Error("Default conferencing app not set");
}
const foundApp = getAppFromSlug(defaultApp.appSlug);
const appType = foundApp?.appData?.location?.type;
if (!appType) {
throw new Error(`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[],
},
});
};