* mv getDefaultLocations * fix * 2 more utils * update imports * fix * move getConnectedApps * move handlePaymentSuccess * update imports * fix import * publish platform libraries
53 lines
1.3 KiB
TypeScript
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[],
|
|
},
|
|
});
|
|
};
|