Files
calendar/packages/trpc/server/routers/loggedInViewer/checkForInvalidAppCredentials.ts
T
aedc88f975 feat: show top banner for broken integrations [Cal 3125] (#13720)
* added InvalidAppCredentialBanner

* Create InvalidAppCredentialsBanner.tsx

* Update getUserTopBanners.handler.ts

* Create checkForInvalidAppCredentials.ts

* Update common.json

* Update common.json

* Update getUserTopBanners.handler.ts

* Update checkForInvalidAppCredentials.ts

* also included team's credentials

* reverse yarnlock changes

* fix .env

* fixed types

* chore: translation

---------

Co-authored-by: Udit Takkar <udit222001@gmail.com>
2024-02-29 19:58:46 +00: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/trpc";
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;
};