From 208d040f6fdc9682bf1349a914cf39b2bfda4f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20L=C3=B3pez?= Date: Thu, 12 Oct 2023 13:22:20 -0700 Subject: [PATCH] fix: added missing prisma imports (#11867) --- apps/api/pages/api/event-types/_post.ts | 4 ++-- .../event-types/_utils/checkParentEventOwnership.ts | 10 +++++++--- .../api/event-types/_utils/checkUserMembership.ts | 11 ++++++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/apps/api/pages/api/event-types/_post.ts b/apps/api/pages/api/event-types/_post.ts index f81af6171a..79a537c420 100644 --- a/apps/api/pages/api/event-types/_post.ts +++ b/apps/api/pages/api/event-types/_post.ts @@ -284,8 +284,8 @@ async function postHandler(req: NextApiRequest) { await checkPermissions(req); if (parsedBody.parentId) { - await checkParentEventOwnership(parsedBody.parentId, userId); - await checkUserMembership(parsedBody.parentId, parsedBody.userId); + await checkParentEventOwnership(req); + await checkUserMembership(req); } if (isAdmin && parsedBody.userId) { diff --git a/apps/api/pages/api/event-types/_utils/checkParentEventOwnership.ts b/apps/api/pages/api/event-types/_utils/checkParentEventOwnership.ts index 15ada70097..2e91d789b7 100644 --- a/apps/api/pages/api/event-types/_utils/checkParentEventOwnership.ts +++ b/apps/api/pages/api/event-types/_utils/checkParentEventOwnership.ts @@ -1,17 +1,21 @@ +import type { NextApiRequest } from "next"; + import { HttpError } from "@calcom/lib/http-error"; /** * Checks if a user, identified by the provided userId, has ownership (or admin rights) over * the team associated with the event type identified by the parentId. * - * @param parentId - The ID of the parent event type. - * @param userId - The ID of the user. + * @param req - The current request * * @throws {HttpError} If the parent event type is not found, * if the parent event type doesn't belong to any team, * or if the user doesn't have ownership or admin rights to the associated team. */ -export default async function checkParentEventOwnership(parentId: number, userId: number) { +export default async function checkParentEventOwnership(req: NextApiRequest) { + const { userId, prisma, body } = req; + /** These are already parsed upstream, we can assume they're good here. */ + const parentId = Number(body.parentId); const parentEventType = await prisma.eventType.findUnique({ where: { id: parentId, diff --git a/apps/api/pages/api/event-types/_utils/checkUserMembership.ts b/apps/api/pages/api/event-types/_utils/checkUserMembership.ts index ad449b42b3..d76fcb89ad 100644 --- a/apps/api/pages/api/event-types/_utils/checkUserMembership.ts +++ b/apps/api/pages/api/event-types/_utils/checkUserMembership.ts @@ -1,17 +1,22 @@ +import type { NextApiRequest } from "next"; + import { HttpError } from "@calcom/lib/http-error"; /** * Checks if a user, identified by the provided userId, is a member of the team associated * with the event type identified by the parentId. * - * @param parentId - The ID of the event type. - * @param userId - The ID of the user. + * @param req - The current request * * @throws {HttpError} If the event type is not found, * if the event type doesn't belong to any team, * or if the user isn't a member of the associated team. */ -export default async function checkUserMembership(parentId: number, userId?: number) { +export default async function checkUserMembership(req: NextApiRequest) { + const { prisma, body } = req; + /** These are already parsed upstream, we can assume they're good here. */ + const parentId = Number(body.parentId); + const userId = Number(body.userId); const parentEventType = await prisma.eventType.findUnique({ where: { id: parentId,