* experiment: cold start perf * fix: update failing test * chore: add database indexes * chore: use json protocol and add query batching back * Update [status].tsx * Update [trpc].ts * Delete getSlimSession.ts * Update createContext.ts * remove trpc caller * correctly import Prisma * lazy ethRouter * replace crypto with md5 * import fixes * public event endpoint refactor * Update yarn.lock * Update yarn.lock * Using yarn.lock from main --------- Co-authored-by: Omar López <zomars@me.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: Efraín Rochín <roae.85@gmail.com> Co-authored-by: Keith Williams <keithwillcode@gmail.com>
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import type { AppCategories } from "@prisma/client";
|
|
import type { Prisma } from "@prisma/client";
|
|
import type { PrismaClient } from "@prisma/client";
|
|
|
|
import { appKeysSchemas } from "@calcom/app-store/apps.keys-schemas.generated";
|
|
import { getLocalAppMetadata } from "@calcom/app-store/utils";
|
|
|
|
// import prisma from "@calcom/prisma";
|
|
import { TRPCError } from "@trpc/server";
|
|
|
|
import type { TrpcSessionUser } from "../../../trpc";
|
|
import type { TSaveKeysInputSchema } from "./saveKeys.schema";
|
|
|
|
type SaveKeysOptions = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser>;
|
|
prisma: PrismaClient;
|
|
};
|
|
input: TSaveKeysInputSchema;
|
|
};
|
|
|
|
export const saveKeysHandler = async ({ ctx, input }: SaveKeysOptions) => {
|
|
const keysSchema = appKeysSchemas[input.dirName as keyof typeof appKeysSchemas];
|
|
const keys = keysSchema.parse(input.keys);
|
|
|
|
// Get app name from metadata
|
|
const localApps = getLocalAppMetadata();
|
|
const appMetadata = localApps.find((localApp) => localApp.slug === input.slug);
|
|
|
|
if (!appMetadata?.dirName && appMetadata?.categories)
|
|
throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: "App metadata could not be found" });
|
|
|
|
await ctx.prisma.app.upsert({
|
|
where: {
|
|
slug: input.slug,
|
|
},
|
|
update: { keys, ...(input.fromEnabled && { enabled: true }) },
|
|
create: {
|
|
slug: input.slug,
|
|
dirName: appMetadata?.dirName || appMetadata?.slug || "",
|
|
categories:
|
|
(appMetadata?.categories as AppCategories[]) ||
|
|
([appMetadata?.category] as AppCategories[]) ||
|
|
undefined,
|
|
keys: (input.keys as Prisma.InputJsonObject) || undefined,
|
|
...(input.fromEnabled && { enabled: true }),
|
|
},
|
|
});
|
|
};
|