fix: added missing prisma imports (#11867)

This commit is contained in:
Omar López 2023-10-12 13:22:20 -07:00 committed by GitHub
parent 8ebcfbb8d1
commit 208d040f6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 8 deletions

View File

@ -284,8 +284,8 @@ async function postHandler(req: NextApiRequest) {
await checkPermissions(req); await checkPermissions(req);
if (parsedBody.parentId) { if (parsedBody.parentId) {
await checkParentEventOwnership(parsedBody.parentId, userId); await checkParentEventOwnership(req);
await checkUserMembership(parsedBody.parentId, parsedBody.userId); await checkUserMembership(req);
} }
if (isAdmin && parsedBody.userId) { if (isAdmin && parsedBody.userId) {

View File

@ -1,17 +1,21 @@
import type { NextApiRequest } from "next";
import { HttpError } from "@calcom/lib/http-error"; import { HttpError } from "@calcom/lib/http-error";
/** /**
* Checks if a user, identified by the provided userId, has ownership (or admin rights) over * 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. * the team associated with the event type identified by the parentId.
* *
* @param parentId - The ID of the parent event type. * @param req - The current request
* @param userId - The ID of the user.
* *
* @throws {HttpError} If the parent event type is not found, * @throws {HttpError} If the parent event type is not found,
* if the parent event type doesn't belong to any team, * 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. * 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({ const parentEventType = await prisma.eventType.findUnique({
where: { where: {
id: parentId, id: parentId,

View File

@ -1,17 +1,22 @@
import type { NextApiRequest } from "next";
import { HttpError } from "@calcom/lib/http-error"; import { HttpError } from "@calcom/lib/http-error";
/** /**
* Checks if a user, identified by the provided userId, is a member of the team associated * Checks if a user, identified by the provided userId, is a member of the team associated
* with the event type identified by the parentId. * with the event type identified by the parentId.
* *
* @param parentId - The ID of the event type. * @param req - The current request
* @param userId - The ID of the user.
* *
* @throws {HttpError} If the event type is not found, * @throws {HttpError} If the event type is not found,
* if the event type doesn't belong to any team, * if the event type doesn't belong to any team,
* or if the user isn't a member of the associated 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({ const parentEventType = await prisma.eventType.findUnique({
where: { where: {
id: parentId, id: parentId,