* move delegation credential repository to features * mv credential repository to features * update imports * mv * fix * fix * fix * fix * fix * update imports * update imports * update eslint rule * fix * fix * mv getConnectedDestinationCalendars * fix import errors * mv getCalendarsEvents * remove getUsersCredentials * wip * revert eslint rule change for now * fix type checks * fix * format * cleanup * fix * fix * fix * fix * fix tests * migrate getUserAvailability * migrate * fix tests * fix type checks * fix * fix * migrate crmManager * update imports * migrate raqbUtils to appstore * migrate getLuckyUser to features * migrate findTeamMembersMatchingAttributeLogic to appstore * update imports * fix * fix * fix test * fix unit tests * fix * fix * add eslint config
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { getUsersCredentialsIncludeServiceAccountKey } from "@calcom/app-store/delegationCredential";
|
|
import getApps from "@calcom/app-store/utils";
|
|
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;
|
|
// getApps need credentials with service account key, but we are filtering credentials out already before returning from this fn
|
|
const credentials = await getUsersCredentialsIncludeServiceAccountKey(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,
|
|
};
|
|
};
|