Files
calendar/packages/trpc/server/routers/viewer/apps/queryForDependencies.handler.ts
T
Benny JooandGitHub bb68cd73ef refactor: circular deps between app store and lib [6] (#23971)
* 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
2025-10-09 14:02:12 +00:00

44 lines
1.3 KiB
TypeScript

import { getAppFromSlug } from "@calcom/app-store/utils";
import { getAllDelegationCredentialsForUserByAppSlug } from "@calcom/app-store/delegationCredential";
import { prisma } from "@calcom/prisma";
import type { TrpcSessionUser } from "../../../types";
import type { TQueryForDependenciesInputSchema } from "./queryForDependencies.schema";
type QueryForDependenciesOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
input: TQueryForDependenciesInputSchema;
};
export const queryForDependenciesHandler = async ({ ctx, input }: QueryForDependenciesOptions) => {
if (!input) return;
const dependencyData: { name: string; slug: string; installed: boolean }[] = [];
await Promise.all(
input.map(async (dependency) => {
const appId = dependency;
const dbCredential = await prisma.credential.findFirst({
where: {
appId,
userId: ctx.user.id,
},
});
const delegationCredentials = await getAllDelegationCredentialsForUserByAppSlug({
user: ctx.user,
appSlug: appId,
});
const appInstalled = !!dbCredential || !!delegationCredentials.length;
const app = getAppFromSlug(dependency);
dependencyData.push({ name: app?.name || dependency, slug: dependency, installed: !!appInstalled });
})
);
return dependencyData;
};