fix: to allow paypal install on team when user already installed (#16553)

* fix to allow paypal install on team when user already installed

* handle if parseInt fails

* Update add.ts

---------

Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
This commit is contained in:
Vijay
2024-09-11 00:06:10 +09:00
committed by GitHub
co-authored by Anik Dhabal Babu
parent 97630e8add
commit c056cabbbd
+8 -1
View File
@@ -1,5 +1,6 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { throwIfNotHaveAdminAccessToTeam } from "@calcom/app-store/_utils/throwIfNotHaveAdminAccessToTeam";
import prisma from "@calcom/prisma";
import config from "../config.json";
@@ -8,12 +9,18 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
if (!req.session?.user?.id) {
return res.status(401).json({ message: "You must be logged in to do this" });
}
const { teamId } = req.query;
await throwIfNotHaveAdminAccessToTeam({ teamId: Number(teamId) ?? null, userId: req.session.user.id });
const installForObject = teamId ? { teamId: Number(teamId) } : { userId: req.session.user.id };
const appType = config.type;
try {
const alreadyInstalled = await prisma.credential.findFirst({
where: {
type: appType,
userId: req.session.user.id,
...installForObject,
},
});
if (alreadyInstalled) {