Files
cal.diy/packages/trpc/server/routers/viewer/me/checkForInvalidAppCredentials.ts
T
Keith WilliamsandDevin AI 825f55c0a1 fix: extract shared types to non-React modules to fix circular dependencies (#26083)
- Move InvalidAppCredentialBannerProps to packages/features/users/types/invalidAppCredentials.ts
- Add WorkflowListType to packages/features/ee/workflows/lib/types.ts
- Update server file imports to use new type locations
- Update React component imports to re-export from new locations

This fixes circular dependencies where server files were importing from React
component modules that import from @calcom/trpc, creating:
server -> component -> @calcom/trpc -> react -> server (circular)

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2025-12-21 01:43:49 +05:30

50 lines
1.4 KiB
TypeScript

import { getAppFromSlug } from "@calcom/app-store/utils";
import { type InvalidAppCredentialBannerProps } from "@calcom/features/users/types/invalidAppCredentials";
import { prisma } from "@calcom/prisma";
import { MembershipRole } from "@calcom/prisma/enums";
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
type checkInvalidAppCredentialsOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
};
export const checkInvalidAppCredentials = async ({ ctx }: checkInvalidAppCredentialsOptions) => {
const userId = ctx.user.id;
// First get the teams where user is admin/owner
const userTeamIds = await prisma.membership.findMany({
where: {
userId: userId,
accepted: true,
role: { in: [MembershipRole.ADMIN, MembershipRole.OWNER] },
},
select: {
teamId: true,
},
});
const apps = await prisma.credential.findMany({
where: {
OR: [{ userId }, { teamId: { in: userTeamIds.map((membership) => membership.teamId) } }],
invalid: true,
},
select: {
appId: true,
},
});
const appNamesAndSlugs: InvalidAppCredentialBannerProps[] = [];
for (const app of apps) {
if (app.appId) {
const appId = app.appId;
const appMeta = await getAppFromSlug(appId);
const name = appMeta ? appMeta.name : appId;
appNamesAndSlugs.push({ slug: appId, name });
}
}
return appNamesAndSlugs;
};