Files
calendar/packages/trpc/server/routers/viewer/apps/appById.handler.ts
T
3c1297aa72 fix: calcom trpc sessio circle dep (#19893)
* fix trpc session circle dep

* fixes trpc session cirlce dep

* fix relative imports

* fix more imports to use types and not trpc

* fix exports

* Fixed types

---------

Co-authored-by: Keith Williams <keithwillcode@gmail.com>
2025-03-19 05:50:22 -03:00

33 lines
1009 B
TypeScript

import getApps from "@calcom/app-store/utils";
import { getUsersCredentials } from "@calcom/lib/server/getUsersCredentials";
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
import { TRPCError } from "@trpc/server";
import type { TAppByIdInputSchema } from "./appById.schema";
type AppByIdOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
input: TAppByIdInputSchema;
};
export const appByIdHandler = async ({ ctx, input }: AppByIdOptions) => {
const { user } = ctx;
const appId = input.appId;
const credentials = await getUsersCredentials(user);
const apps = getApps(credentials);
const appFromDb = apps.find((app) => app.slug === appId);
if (!appFromDb) {
throw new TRPCError({ code: "BAD_REQUEST", message: `Could not find app ${appId}` });
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { credential: _, credentials: _1, ...app } = appFromDb;
return {
isInstalled: appFromDb.credentials.length,
...app,
};
};