Files
calendar/packages/trpc/server/routers/viewer/me/checkForInvalidAppCredentials.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

53 lines
1.4 KiB
TypeScript

import { getAppFromSlug } from "@calcom/app-store/utils";
import { type InvalidAppCredentialBannerProps } from "@calcom/features/users/components/InvalidAppCredentialsBanner";
import { prisma } from "@calcom/prisma";
import { MembershipRole } from "@calcom/prisma/client";
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;
const apps = await prisma.credential.findMany({
where: {
OR: [
{
userId: userId,
},
{
team: {
members: {
some: {
userId: userId,
accepted: true,
role: { in: [MembershipRole.ADMIN, MembershipRole.OWNER] },
},
},
},
},
],
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;
};