fix(paypal/add): prisma count is slow

11791-cal-2603-refactor-paypal-to-use-their-oauth-and-not-require-users-to-make-an-app
Morgan Vernay 2023-10-12 17:20:44 +03:00
parent fbdaba65d3
commit 9941186a74
1 changed files with 5 additions and 3 deletions

View File

@ -13,13 +13,15 @@ async function getHandler(req: NextApiRequest, res: NextApiResponse) {
return res.status(401).json({ message: "You must be logged in to do this" });
}
try {
const alreadyInstalled =
(await prisma.credential.count({
const alreadyInstalled = Boolean(
await prisma.credential.findFirst({
select: { id: true },
where: {
appId: config.slug,
...(Boolean(teamId) ? { AND: [{ userId: userId }, { teamId }] } : { userId: userId }),
},
})) > 0;
})
);
if (alreadyInstalled) {
throw new Error("App is already installed");