feat: dynamic prisma
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
afterEach((done) => {
|
||||
prisma.$disconnect().then();
|
||||
prisma().$disconnect().then();
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { NextMiddleware } from "next-api-middleware";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
// This replaces the prisma client for the cusotm one if the customApiId is valid
|
||||
export const customApiEndpoints: NextMiddleware = async (req, res, next) => {
|
||||
const {
|
||||
query: { customApiId },
|
||||
} = req;
|
||||
// If no custom api Id is provided, return the regular cal.com prisma client.
|
||||
if (!customApiId) {
|
||||
req.prisma = prisma();
|
||||
await next();
|
||||
}
|
||||
// Hardcoded new database, this should be a dynamic call to console prisma/api?
|
||||
const newDatabseUrl = process.env.DATABASE_PROD_URL;
|
||||
req.prisma = prisma(newDatabseUrl);
|
||||
|
||||
await next();
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
import type { IncomingMessage } from "http";
|
||||
import { NextMiddleware } from "next-api-middleware";
|
||||
|
||||
import type { PrismaClient } from ".prisma/client";
|
||||
|
||||
/** @todo figure how to use the one from `@calcom/types`fi */
|
||||
/** @todo: remove once `@calcom/types` is updated with it.*/
|
||||
declare module "next" {
|
||||
export interface NextApiRequest extends IncomingMessage {
|
||||
userId: number;
|
||||
method: string;
|
||||
prisma: PrismaClient;
|
||||
body: any;
|
||||
query: { [key: string]: string | string[] };
|
||||
}
|
||||
}
|
||||
export const extendRequest: NextMiddleware = async (req, res, next) => {
|
||||
await next();
|
||||
};
|
||||
+13
-11
@@ -1,18 +1,19 @@
|
||||
import type { IncomingMessage } from "http";
|
||||
// import type { IncomingMessage } from "http";
|
||||
import { NextMiddleware } from "next-api-middleware";
|
||||
|
||||
import { hashAPIKey } from "@calcom/ee/lib/api/apiKeys";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
/** @todo figure how to use the one from `@calcom/types`fi */
|
||||
/** @todo: remove once `@calcom/types` is updated with it.*/
|
||||
declare module "next" {
|
||||
export interface NextApiRequest extends IncomingMessage {
|
||||
userId: number;
|
||||
method: string;
|
||||
query: { [key: string]: string | string[] };
|
||||
}
|
||||
}
|
||||
// // import prisma from "@calcom/prisma";
|
||||
|
||||
// /** @todo figure how to use the one from `@calcom/types`fi */
|
||||
// /** @todo: remove once `@calcom/types` is updated with it.*/
|
||||
// declare module "next" {
|
||||
// export interface NextApiRequest extends IncomingMessage {
|
||||
// userId: number;
|
||||
// method: string;
|
||||
// query: { [key: string]: string | string[] };
|
||||
// }
|
||||
// }
|
||||
|
||||
// Used to check if the apiKey is not expired, could be extracted if reused. but not for now.
|
||||
export const dateNotInPast = function (date: Date) {
|
||||
@@ -24,6 +25,7 @@ export const dateNotInPast = function (date: Date) {
|
||||
|
||||
// This verifies the apiKey and sets the user if it is valid.
|
||||
export const verifyApiKey: NextMiddleware = async (req, res, next) => {
|
||||
const { prisma } = req;
|
||||
if (!req.query.apiKey) return res.status(401).json({ message: "No apiKey provided" });
|
||||
// We remove the prefix from the user provided api_key. If no env set default to "cal_"
|
||||
const strippedApiKey = `${req.query.apiKey}`.replace(process.env.API_KEY_PREFIX || "cal_", "");
|
||||
|
||||
@@ -2,6 +2,8 @@ import { label } from "next-api-middleware";
|
||||
|
||||
import { addRequestId } from "./addRequestid";
|
||||
import { captureErrors } from "./captureErrors";
|
||||
import { customApiEndpoints } from "./customApiEndpoints";
|
||||
import { extendRequest } from "./extendRequest";
|
||||
import {
|
||||
HTTP_POST,
|
||||
HTTP_DELETE,
|
||||
@@ -22,9 +24,11 @@ const withMiddleware = label(
|
||||
HTTP_DELETE,
|
||||
addRequestId,
|
||||
verifyApiKey,
|
||||
customApiEndpoints,
|
||||
extendRequest,
|
||||
sentry: captureErrors,
|
||||
},
|
||||
["sentry", "verifyApiKey", "addRequestId"] // <-- Provide a list of middleware to call automatically
|
||||
["sentry", "customApiEndpoints", "verifyApiKey", "addRequestId", "extendRequest"] // <-- Provide a list of middleware to call automatically
|
||||
);
|
||||
|
||||
export { withMiddleware };
|
||||
|
||||
@@ -3,6 +3,6 @@ import { UserPermissionRole } from "@prisma/client";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
export const isAdminGuard = async (userId: number) => {
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
const user = await prisma().user.findUnique({ where: { id: userId } });
|
||||
return user?.role === UserPermissionRole.ADMIN;
|
||||
};
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
// // import prisma from "@calcom/prisma";
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { AttendeeResponse } from "@lib/types";
|
||||
import { isAdminGuard } from "@lib/utils/isAdmin";
|
||||
import { schemaAttendeeEditBodyParams, schemaAttendeeReadPublic } from "@lib/validations/attendee";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
@@ -11,9 +11,10 @@ import {
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
export async function attendeeById(
|
||||
{ method, query, body, userId }: NextApiRequest,
|
||||
{ method, query, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<AttendeeResponse>
|
||||
) {
|
||||
const isAdmin = await isAdminGuard(userId);
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
if (!safeQuery.success) {
|
||||
res.status(400).json({ error: safeQuery.error });
|
||||
@@ -34,8 +35,10 @@ export async function attendeeById(
|
||||
.map((attendee) => attendee.id)
|
||||
);
|
||||
// @note: Here we make sure to only return attendee's of the user's own bookings.
|
||||
if (!userBookingsAttendeeIds.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" });
|
||||
else {
|
||||
if (!isAdmin) {
|
||||
if (!userBookingsAttendeeIds.includes(safeQuery.data.id))
|
||||
res.status(401).json({ message: "Unauthorized" });
|
||||
} else {
|
||||
switch (method) {
|
||||
/**
|
||||
* @swagger
|
||||
|
||||
@@ -1,24 +1,31 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import db from "@calcom/prisma";
|
||||
|
||||
// import db from "@calcom/prisma";
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { AttendeeResponse, AttendeesResponse } from "@lib/types";
|
||||
import type { AttendeeResponse, AttendeesResponse } from "@lib/types";
|
||||
import { isAdminGuard } from "@lib/utils/isAdmin";
|
||||
import { schemaAttendeeCreateBodyParams, schemaAttendeeReadPublic } from "@lib/validations/attendee";
|
||||
|
||||
async function createOrlistAllAttendees(
|
||||
{ method, userId, body }: NextApiRequest,
|
||||
{ method, userId, body, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<AttendeesResponse | AttendeeResponse>
|
||||
) {
|
||||
const userBookings = await db.booking.findMany({
|
||||
where: {
|
||||
userId,
|
||||
},
|
||||
include: {
|
||||
attendees: true,
|
||||
},
|
||||
});
|
||||
const attendees = userBookings.map((booking) => booking.attendees).flat();
|
||||
const isAdmin = await isAdminGuard(userId);
|
||||
let attendees;
|
||||
if (!isAdmin) {
|
||||
const userBookings = await prisma.booking.findMany({
|
||||
where: {
|
||||
userId,
|
||||
},
|
||||
include: {
|
||||
attendees: true,
|
||||
},
|
||||
});
|
||||
attendees = userBookings.map((booking) => booking.attendees).flat();
|
||||
} else {
|
||||
const data = await prisma.attendee.findMany();
|
||||
attendees = data.map((attendee) => schemaAttendeeReadPublic.parse(attendee));
|
||||
}
|
||||
if (method === "GET") {
|
||||
/**
|
||||
* @swagger
|
||||
@@ -37,12 +44,7 @@ async function createOrlistAllAttendees(
|
||||
* description: No attendees were found
|
||||
*/
|
||||
if (attendees) res.status(200).json({ attendees });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No Attendees were found",
|
||||
error,
|
||||
});
|
||||
else (error: Error) => res.status(400).json({ error });
|
||||
} else if (method === "POST") {
|
||||
/**
|
||||
* @swagger
|
||||
@@ -90,16 +92,40 @@ async function createOrlistAllAttendees(
|
||||
res.status(400).json({ message: "Invalid request body", error: safePost.error });
|
||||
return;
|
||||
}
|
||||
const userWithBookings = await db.user.findUnique({ where: { id: userId }, include: { bookings: true } });
|
||||
if (!userWithBookings) {
|
||||
res.status(404).json({ message: "User not found" });
|
||||
return;
|
||||
}
|
||||
const userBookingIds = userWithBookings.bookings.map((booking: { id: number }) => booking.id).flat();
|
||||
// Here we make sure to only return attendee's of the user's own bookings.
|
||||
if (!userBookingIds.includes(safePost.data.bookingId)) res.status(401).json({ message: "Unauthorized" });
|
||||
else {
|
||||
const data = await db.attendee.create({
|
||||
if (!isAdmin) {
|
||||
const userWithBookings = await prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
include: { bookings: true },
|
||||
});
|
||||
if (!userWithBookings) {
|
||||
res.status(404).json({ message: "User not found" });
|
||||
return;
|
||||
}
|
||||
const userBookingIds = userWithBookings.bookings.map((booking: { id: number }) => booking.id).flat();
|
||||
// Here we make sure to only return attendee's of the user's own bookings.
|
||||
if (!userBookingIds.includes(safePost.data.bookingId))
|
||||
res.status(401).json({ message: "Unauthorized" });
|
||||
else {
|
||||
const data = await prisma.attendee.create({
|
||||
data: {
|
||||
email: safePost.data.email,
|
||||
name: safePost.data.name,
|
||||
timeZone: safePost.data.timeZone,
|
||||
booking: { connect: { id: safePost.data.bookingId } },
|
||||
},
|
||||
});
|
||||
const attendee = schemaAttendeeReadPublic.parse(data);
|
||||
|
||||
if (attendee) {
|
||||
res.status(201).json({
|
||||
attendee,
|
||||
message: "Attendee created successfully",
|
||||
});
|
||||
} else (error: Error) => res.status(400).json({ error });
|
||||
}
|
||||
} else {
|
||||
// @todo: check real availability times before booking
|
||||
const data = await prisma.attendee.create({
|
||||
data: {
|
||||
email: safePost.data.email,
|
||||
name: safePost.data.name,
|
||||
@@ -114,13 +140,7 @@ async function createOrlistAllAttendees(
|
||||
attendee,
|
||||
message: "Attendee created successfully",
|
||||
});
|
||||
} else {
|
||||
(error: Error) =>
|
||||
res.status(400).json({
|
||||
message: "Could not create new attendee",
|
||||
error,
|
||||
});
|
||||
}
|
||||
} else (error: Error) => res.status(400).json({ error });
|
||||
}
|
||||
} else res.status(405).json({ message: `Method ${method} not allowed` });
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
// // import prisma from "@calcom/prisma";
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { AvailabilityResponse } from "@lib/types";
|
||||
import {
|
||||
@@ -14,7 +13,7 @@ import {
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
export async function availabilityById(
|
||||
{ method, query, body, userId }: NextApiRequest,
|
||||
{ method, query, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<AvailabilityResponse>
|
||||
) {
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
// import prisma from "@calcom/prisma";
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { AvailabilityResponse, AvailabilitiesResponse } from "@lib/types";
|
||||
import {
|
||||
@@ -10,7 +9,7 @@ import {
|
||||
} from "@lib/validations/availability";
|
||||
|
||||
async function createOrlistAllAvailabilities(
|
||||
{ method, body, userId }: NextApiRequest,
|
||||
{ method, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<AvailabilitiesResponse | AvailabilityResponse>
|
||||
) {
|
||||
if (method === "GET") {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { BookingReferenceResponse } from "@lib/types";
|
||||
import {
|
||||
@@ -14,7 +12,7 @@ import {
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
export async function bookingReferenceById(
|
||||
{ method, query, body, userId }: NextApiRequest,
|
||||
{ method, query, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<BookingReferenceResponse>
|
||||
) {
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
@@ -64,7 +62,6 @@ export async function bookingReferenceById(
|
||||
.then((data) => schemaBookingReferenceReadPublic.parse(data))
|
||||
.then((booking_reference) => res.status(200).json({ booking_reference }))
|
||||
.catch((error: Error) => {
|
||||
console.log(error);
|
||||
res.status(404).json({
|
||||
message: `BookingReference with id: ${safeQuery.data.id} not found`,
|
||||
error,
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { BookingReferenceResponse, BookingReferencesResponse } from "@lib/types";
|
||||
import {
|
||||
@@ -10,7 +8,7 @@ import {
|
||||
} from "@lib/validations/booking-reference";
|
||||
|
||||
async function createOrlistAllBookingReferences(
|
||||
{ method, userId, body }: NextApiRequest,
|
||||
{ method, userId, body, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<BookingReferencesResponse | BookingReferenceResponse>
|
||||
) {
|
||||
const userWithBookings = await prisma.user.findUnique({
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
// import prisma from "@calcom/prisma";
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { BookingResponse } from "@lib/types";
|
||||
import { isAdminGuard } from "@lib/utils/isAdmin";
|
||||
import { schemaBookingEditBodyParams, schemaBookingReadPublic } from "@lib/validations/booking";
|
||||
import {
|
||||
schemaQueryIdParseInt,
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
export async function bookingById(
|
||||
{ method, query, body, userId }: NextApiRequest,
|
||||
{ method, query, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<BookingResponse>
|
||||
) {
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
@@ -25,8 +25,11 @@ export async function bookingById(
|
||||
});
|
||||
if (!userWithBookings) throw new Error("User not found");
|
||||
const userBookingIds = userWithBookings.bookings.map((booking: { id: number }) => booking.id).flat();
|
||||
if (!userBookingIds.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" });
|
||||
else {
|
||||
const isAdmin = await isAdminGuard(userId);
|
||||
|
||||
if (!isAdmin) {
|
||||
if (!userBookingIds.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" });
|
||||
} else {
|
||||
switch (method) {
|
||||
/**
|
||||
* @swagger
|
||||
|
||||
+41
-26
@@ -1,16 +1,16 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
// import prisma from "@calcom/prisma";
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { BookingResponse, BookingsResponse } from "@lib/types";
|
||||
import type { BookingResponse, BookingsResponse } from "@lib/types";
|
||||
import { isAdminGuard } from "@lib/utils/isAdmin";
|
||||
import { schemaBookingCreateBodyParams, schemaBookingReadPublic } from "@lib/validations/booking";
|
||||
|
||||
async function createOrlistAllBookings(
|
||||
{ method, body, userId }: NextApiRequest,
|
||||
{ method, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<BookingsResponse | BookingResponse>
|
||||
) {
|
||||
console.log("userIduserId", userId);
|
||||
const isAdmin = await isAdminGuard(userId);
|
||||
if (method === "GET") {
|
||||
/**
|
||||
* @swagger
|
||||
@@ -28,15 +28,29 @@ async function createOrlistAllBookings(
|
||||
* 404:
|
||||
* description: No bookings were found
|
||||
*/
|
||||
const data = await prisma.booking.findMany({ where: { userId } });
|
||||
const bookings = data.map((booking) => schemaBookingReadPublic.parse(booking));
|
||||
if (bookings) res.status(200).json({ bookings });
|
||||
else
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No Bookings were found",
|
||||
error,
|
||||
});
|
||||
if (!isAdmin) {
|
||||
const data = await prisma.booking.findMany({ where: { userId } });
|
||||
const bookings = data.map((booking) => schemaBookingReadPublic.parse(booking));
|
||||
if (bookings) res.status(200).json({ bookings });
|
||||
else {
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No Bookings were found",
|
||||
error,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
const data = await prisma.booking.findMany();
|
||||
const bookings = data.map((booking) => schemaBookingReadPublic.parse(booking));
|
||||
if (bookings) res.status(200).json({ bookings });
|
||||
else {
|
||||
(error: Error) =>
|
||||
res.status(404).json({
|
||||
message: "No Bookings were found",
|
||||
error,
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (method === "POST") {
|
||||
/**
|
||||
* @swagger
|
||||
@@ -77,19 +91,20 @@ async function createOrlistAllBookings(
|
||||
res.status(400).json({ message: "Bad request. Booking body is invalid." });
|
||||
return;
|
||||
}
|
||||
safe.data.userId = userId;
|
||||
const data = await prisma.booking.create({ data: { ...safe.data } });
|
||||
const booking = schemaBookingReadPublic.parse(data);
|
||||
if (!isAdmin) {
|
||||
safe.data.userId = userId;
|
||||
const data = await prisma.booking.create({ data: { ...safe.data } });
|
||||
const booking = schemaBookingReadPublic.parse(data);
|
||||
|
||||
if (booking) res.status(201).json({ booking, message: "Booking created successfully" });
|
||||
else
|
||||
(error: Error) => {
|
||||
console.log(error);
|
||||
res.status(400).json({
|
||||
message: "Could not create new booking",
|
||||
error,
|
||||
});
|
||||
};
|
||||
if (booking) res.status(201).json({ booking, message: "Booking created successfully" });
|
||||
else (error: Error) => res.status(400).json({ error });
|
||||
} else {
|
||||
const data = await prisma.booking.create({ data: { ...safe.data } });
|
||||
const booking = schemaBookingReadPublic.parse(data);
|
||||
|
||||
if (booking) res.status(201).json({ booking, message: "Booking created successfully" });
|
||||
else (error: Error) => res.status(400).json({ error });
|
||||
}
|
||||
} else res.status(405).json({ message: `Method ${method} not allowed` });
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { EventTypeCustomInputResponse } from "@lib/types";
|
||||
import {
|
||||
@@ -72,7 +70,7 @@ import {
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
async function eventTypeById(
|
||||
{ method, query, body, userId }: NextApiRequest,
|
||||
{ method, query, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<EventTypeCustomInputResponse>
|
||||
) {
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { EventTypeCustomInputResponse, EventTypeCustomInputsResponse } from "@lib/types";
|
||||
import {
|
||||
@@ -10,7 +8,7 @@ import {
|
||||
} from "@lib/validations/event-type-custom-input";
|
||||
|
||||
async function createOrlistAllEventTypeCustomInputs(
|
||||
{ userId, method, body }: NextApiRequest,
|
||||
{ userId, method, body, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<EventTypeCustomInputsResponse | EventTypeCustomInputResponse>
|
||||
) {
|
||||
const data = await prisma.eventType.findMany({ where: { userId } });
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { DestinationCalendarResponse } from "@lib/types";
|
||||
import {
|
||||
@@ -14,7 +12,7 @@ import {
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
export async function destionationCalendarById(
|
||||
{ method, query, body, userId }: NextApiRequest,
|
||||
{ method, query, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<DestinationCalendarResponse>
|
||||
) {
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { DestinationCalendarResponse, DestinationCalendarsResponse } from "@lib/types";
|
||||
import {
|
||||
@@ -10,7 +8,7 @@ import {
|
||||
} from "@lib/validations/destination-calendar";
|
||||
|
||||
async function createOrlistAllDestinationCalendars(
|
||||
{ method, body, userId }: NextApiRequest,
|
||||
{ method, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<DestinationCalendarsResponse | DestinationCalendarResponse>
|
||||
) {
|
||||
if (method === "GET") {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { DailyEventReferenceResponse } from "@lib/types";
|
||||
import {
|
||||
@@ -14,7 +12,7 @@ import {
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
export async function dailyEventReferenceById(
|
||||
{ method, query, body, userId }: NextApiRequest,
|
||||
{ method, query, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<DailyEventReferenceResponse>
|
||||
) {
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { DailyEventReferenceResponse, DailyEventReferencesResponse } from "@lib/types";
|
||||
import {
|
||||
@@ -10,7 +8,7 @@ import {
|
||||
} from "@lib/validations/event-reference";
|
||||
|
||||
async function createOrlistAllDailyEventReferences(
|
||||
{ method, body, userId }: NextApiRequest,
|
||||
{ method, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<DailyEventReferencesResponse | DailyEventReferenceResponse>
|
||||
) {
|
||||
const userBookings = await prisma.booking.findMany({ where: { userId } });
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { EventTypeResponse } from "@lib/types";
|
||||
import { isAdminGuard } from "@lib/utils/isAdmin";
|
||||
@@ -12,7 +10,7 @@ import {
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
export async function eventTypeById(
|
||||
{ method, query, body, userId }: NextApiRequest,
|
||||
{ method, query, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<EventTypeResponse>
|
||||
) {
|
||||
const isAdmin = await isAdminGuard(userId);
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { EventTypeResponse, EventTypesResponse } from "@lib/types";
|
||||
import type { EventTypeResponse, EventTypesResponse } from "@lib/types";
|
||||
import { isAdminGuard } from "@lib/utils/isAdmin";
|
||||
import { schemaEventTypeCreateBodyParams, schemaEventTypeReadPublic } from "@lib/validations/event-type";
|
||||
|
||||
async function createOrlistAllEventTypes(
|
||||
{ method, body, userId }: NextApiRequest,
|
||||
{ method, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<EventTypesResponse | EventTypeResponse>
|
||||
) {
|
||||
const isAdmin = await isAdminGuard(userId);
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { WebhookResponse } from "@lib/types";
|
||||
import { schemaQueryIdAsString } from "@lib/validations/shared/queryIdString";
|
||||
import { schemaWebhookEditBodyParams, schemaWebhookReadPublic } from "@lib/validations/webhook";
|
||||
|
||||
export async function WebhookById(
|
||||
{ method, query, body, userId }: NextApiRequest,
|
||||
{ method, query, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<WebhookResponse>
|
||||
) {
|
||||
const safeQuery = schemaQueryIdAsString.safeParse(query);
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { WebhookResponse, WebhooksResponse } from "@lib/types";
|
||||
import { schemaWebhookCreateBodyParams } from "@lib/validations/webhook";
|
||||
|
||||
async function createOrlistAllWebhooks(
|
||||
{ method, body, userId }: NextApiRequest,
|
||||
{ method, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<WebhooksResponse | WebhookResponse>
|
||||
) {
|
||||
if (method === "GET") {
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { MembershipResponse } from "@lib/types";
|
||||
import { schemaMembershipBodyParams, schemaMembershipPublic } from "@lib/validations/membership";
|
||||
import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString";
|
||||
|
||||
export async function membershipById(
|
||||
{ method, query, body, userId }: NextApiRequest,
|
||||
{ method, query, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<MembershipResponse>
|
||||
) {
|
||||
const safeQuery = schemaQueryIdAsString.safeParse(query);
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { MembershipResponse, MembershipsResponse } from "@lib/types";
|
||||
import { schemaMembershipBodyParams, schemaMembershipPublic } from "@lib/validations/membership";
|
||||
|
||||
async function createOrlistAllMemberships(
|
||||
{ method, body, userId }: NextApiRequest,
|
||||
{ method, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<MembershipsResponse | MembershipResponse>
|
||||
) {
|
||||
if (method === "GET") {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { PaymentResponse } from "@lib/types";
|
||||
import { schemaPaymentPublic } from "@lib/validations/payment";
|
||||
@@ -33,7 +31,7 @@ import {
|
||||
* description: Payment was not found
|
||||
*/
|
||||
export async function paymentById(
|
||||
{ method, query, userId }: NextApiRequest,
|
||||
{ method, query, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<PaymentResponse>
|
||||
) {
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { PaymentsResponse } from "@lib/types";
|
||||
import { schemaPaymentPublic } from "@lib/validations/payment";
|
||||
@@ -21,7 +19,7 @@ import { schemaPaymentPublic } from "@lib/validations/payment";
|
||||
* 404:
|
||||
* description: No payments were found
|
||||
*/
|
||||
async function allPayments({ userId }: NextApiRequest, res: NextApiResponse<PaymentsResponse>) {
|
||||
async function allPayments({ userId, prisma }: NextApiRequest, res: NextApiResponse<PaymentsResponse>) {
|
||||
const userWithBookings = await prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
include: { bookings: true },
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { ScheduleResponse } from "@lib/types";
|
||||
import { schemaScheduleBodyParams, schemaSchedulePublic } from "@lib/validations/schedule";
|
||||
@@ -11,7 +9,7 @@ import {
|
||||
} from "@lib/validations/shared/queryIdTransformParseInt";
|
||||
|
||||
export async function scheduleById(
|
||||
{ method, query, body, userId }: NextApiRequest,
|
||||
{ method, query, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<ScheduleResponse>
|
||||
) {
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { ScheduleResponse, SchedulesResponse } from "@lib/types";
|
||||
import { schemaScheduleBodyParams, schemaSchedulePublic } from "@lib/validations/schedule";
|
||||
|
||||
async function createOrlistAllSchedules(
|
||||
{ method, body, userId }: NextApiRequest,
|
||||
{ method, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<SchedulesResponse | ScheduleResponse>
|
||||
) {
|
||||
if (method === "GET") {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { SelectedCalendarResponse } from "@lib/types";
|
||||
import {
|
||||
@@ -11,7 +9,7 @@ import {
|
||||
import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString";
|
||||
|
||||
export async function selectedCalendarById(
|
||||
{ method, query, body, userId }: NextApiRequest,
|
||||
{ method, query, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<SelectedCalendarResponse>
|
||||
) {
|
||||
const safeQuery = schemaQueryIdAsString.safeParse(query);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { SelectedCalendarResponse, SelectedCalendarsResponse } from "@lib/types";
|
||||
import {
|
||||
@@ -10,7 +8,7 @@ import {
|
||||
} from "@lib/validations/selected-calendar";
|
||||
|
||||
async function createOrlistAllSelectedCalendars(
|
||||
{ method, body, userId }: NextApiRequest,
|
||||
{ method, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<SelectedCalendarsResponse | SelectedCalendarResponse>
|
||||
) {
|
||||
if (method === "GET") {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { TeamResponse } from "@lib/types";
|
||||
import {
|
||||
@@ -72,7 +70,7 @@ import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team";
|
||||
* description: Authorization information is missing or invalid.
|
||||
*/
|
||||
export async function teamById(
|
||||
{ method, query, body, userId }: NextApiRequest,
|
||||
{ method, query, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<TeamResponse>
|
||||
) {
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { TeamResponse, TeamsResponse } from "@lib/types";
|
||||
import { schemaMembershipPublic } from "@lib/validations/membership";
|
||||
import { schemaTeamBodyParams, schemaTeamPublic } from "@lib/validations/team";
|
||||
|
||||
async function createOrlistAllTeams(
|
||||
{ method, body, userId }: NextApiRequest,
|
||||
{ method, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<TeamsResponse | TeamResponse>
|
||||
) {
|
||||
if (method === "GET") {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import type { UserResponse } from "@lib/types";
|
||||
import { isAdminGuard } from "@lib/utils/isAdmin";
|
||||
@@ -12,7 +10,7 @@ import {
|
||||
import { schemaUserEditBodyParams, schemaUserReadPublic } from "@lib/validations/user";
|
||||
|
||||
export async function userById(
|
||||
{ method, query, body, userId }: NextApiRequest,
|
||||
{ method, query, body, userId, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<UserResponse>
|
||||
) {
|
||||
const safeQuery = schemaQueryIdParseInt.safeParse(query);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { UserResponse, UsersResponse } from "@lib/types";
|
||||
import { isAdminGuard } from "@lib/utils/isAdmin";
|
||||
@@ -24,7 +22,7 @@ import { schemaUserReadPublic, schemaUserCreateBodyParams } from "@lib/validatio
|
||||
* description: No users were found
|
||||
*/
|
||||
async function getAllorCreateUser(
|
||||
{ userId, method, body }: NextApiRequest,
|
||||
{ userId, method, body, prisma }: NextApiRequest,
|
||||
res: NextApiResponse<UsersResponse | UserResponse>
|
||||
) {
|
||||
const isAdmin = await isAdminGuard(userId);
|
||||
|
||||
Reference in New Issue
Block a user