From c056cabbbd83fc47b0189058d0ed26d0673eb2a9 Mon Sep 17 00:00:00 2001 From: Vijay Date: Tue, 10 Sep 2024 20:36:10 +0530 Subject: [PATCH] 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> --- packages/app-store/paypal/api/add.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/app-store/paypal/api/add.ts b/packages/app-store/paypal/api/add.ts index bab1b9390c..e2762565d0 100644 --- a/packages/app-store/paypal/api/add.ts +++ b/packages/app-store/paypal/api/add.ts @@ -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) {