Skip to content

Scheduling infrastructure for absolutely everyone.

Refactoring and fixes

zomarsbe3bcf2bf003
diff --git a/.husky/pre-commit b/.husky/pre-commit
deleted file mode 100755
index 025779ed2ba..00000000000
--- a/.husky/pre-commit
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/sh
-. "$(dirname "$0")/_/husky.sh"
-
-yarn pre-commit
diff --git a/.prettierrc.js b/.prettierrc.js
deleted file mode 100644
index 246057aa0c7..00000000000
--- a/.prettierrc.js
+++ /dev/null
@@ -1 +0,0 @@
-module.exports = require("../../packages/config/prettier-preset");
diff --git a/babel.config.js b/babel.config.js
deleted file mode 100644
index 2afcfd24044..00000000000
--- a/babel.config.js
+++ /dev/null
@@ -1,3 +0,0 @@
-module.exports = {
- presets: [["@babel/preset-env", { targets: { node: "current" } }], "@babel/preset-typescript"],
-};
diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts
index 0ee197456c3..0f70c88a8ee 100644
--- a/lib/helpers/verifyApiKey.ts
+++ b/lib/helpers/verifyApiKey.ts
@@ -1,8 +1,17 @@
+import type { IncomingMessage } from "http";
+import type { NextApiRequest, NextApiResponse } from "next";
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 */
+declare module "next" {
+ export interface NextApiRequest extends IncomingMessage {
+ userId: number;
+ }
+}
+
// Used to check if the API key is not expired, could be extracted if reused. but not for now.
export const dateInPast = function (date: Date) {
const now = new Date();
@@ -12,24 +21,21 @@ export const dateInPast = function (date: Date) {
};
// This verifies the API key and sets the user if it is valid.
-export const verifyApiKey: NextMiddleware = async (req, res, next) => {
- if (!req.query.apiKey) res.status(401).json({ message: "No api key provided" });
+export const verifyApiKey: NextMiddleware = async (req: NextApiRequest, res: NextApiResponse, next) => {
+ if (!req.query.apiKey) return res.status(401).json({ message: "No api key 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_", "");
// Hash the key again before matching against the database records.
const hashedKey = hashAPIKey(strippedApiKey);
// Check if the hashed api key exists in database.
- await prisma.apiKey.findUnique({ where: { hashedKey } }).then(async (apiKey) => {
- // If we cannot find any api key. Throw a 401 Unauthorized.
- if (!apiKey) res.status(401).json({ error: "Your api key is not valid" });
- if (apiKey && apiKey.expiresAt && dateInPast(apiKey.expiresAt) && apiKey.userId) {
- // Right now API Keys are user centric, we only allow resources related to this userId throughout the application.
- // if the api key is not expired, and the user id is present in the database.
- // Set the user in the request. as x-calcom-user-id.
- if (apiKey.userId) res.setHeader("X-Calcom-User-ID", apiKey.userId);
-
- // Pass the request to the next middleware.
- await next();
- }
- });
+ const apiKey = await prisma.apiKey.findUnique({ where: { hashedKey } });
+ // If we cannot find any api key. Throw a 401 Unauthorized.
+ if (!apiKey) return res.status(401).json({ error: "Your api key is not valid" });
+ if (apiKey.expiresAt && dateInPast(apiKey.expiresAt)) {
+ return res.status(401).json({ error: "This api key is expired" });
+ }
+ if (!apiKey.userId) return res.status(404).json({ error: "No user found for this api key" });
+ /* We save the user id in the request for later use */
+ req.userId = apiKey.userId;
+ await next();
};
diff --git a/lib/utils/getCalcomUserId.ts b/lib/utils/getCalcomUserId.ts
deleted file mode 100644
index 8670bc8759a..00000000000
--- a/lib/utils/getCalcomUserId.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-import { NextApiResponse } from "next";
-
-export const getCalcomUserId = (res: NextApiResponse): number => res.getHeader("x-calcom-user-id") as number;
diff --git a/package.json b/package.json
index 16dc0f9b9fd..5739292e02a 100644
--- a/package.json
+++ b/package.json
@@ -14,24 +14,17 @@
"lint-fix": "next lint --fix && prettier --write .",
"test": "jest --detectOpenHandles",
"type-check": "tsc --pretty --noEmit",
- "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
- "prepare": "husky install",
- "pre-commit": "next lint"
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
},
"devDependencies": {
- "@babel/core": "^7.17.8",
- "@babel/preset-env": "^7.16.11",
- "@babel/preset-typescript": "^7.16.7",
- "@calcom/prisma": "*",
"@calcom/tsconfig": "*",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"babel-jest": "^27.5.1",
- "husky": "^7.0.4",
"jest": "^27.5.1",
- "node-mocks-http": "^1.11.0",
- "prettier": "^2.6.1"
+ "node-mocks-http": "^1.11.0"
},
"dependencies": {
+ "@calcom/prisma": "*",
"@sentry/nextjs": "^6.19.3",
"next": "^12.1.4",
"next-api-middleware": "^1.0.1",
diff --git a/pages/api/attendees/[id].ts b/pages/api/attendees/[id].ts
index a7b573cc87e..3eba0891f20 100644
--- a/pages/api/attendees/[id].ts
+++ b/pages/api/attendees/[id].ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { AttendeeResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import { schemaAttendeeBodyParams, schemaAttendeePublic } from "@lib/validations/attendee";
import {
schemaQueryIdParseInt,
@@ -93,7 +92,7 @@ export async function attendeeById(req: NextApiRequest, res: NextApiResponse<Att
if (!safeQuery.success) {
throw new Error("Invalid request query", safeQuery.error);
}
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
const userBookings = await prisma.booking.findMany({
where: { userId },
include: { attendees: true },
diff --git a/pages/api/attendees/index.ts b/pages/api/attendees/index.ts
index d96fe3bca47..6a3880bf3ce 100644
--- a/pages/api/attendees/index.ts
+++ b/pages/api/attendees/index.ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { AttendeeResponse, AttendeesResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import { schemaAttendeeBodyParams, schemaAttendeePublic, withValidAttendee } from "@lib/validations/attendee";
/**
@@ -43,7 +42,7 @@ async function createOrlistAllAttendees(
res: NextApiResponse<AttendeesResponse | AttendeeResponse>
) {
const { method } = req;
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
// Here we make sure to only return attendee's of the user's own bookings.
const userBookings = await prisma.booking.findMany({
where: {
@@ -68,7 +67,7 @@ async function createOrlistAllAttendees(
throw new Error("Invalid request body", safe.error);
}
const bookingId = safe.data.bookingId;
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
const userWithBookings = await prisma.user.findUnique({
where: { id: userId },
include: { bookings: true },
diff --git a/pages/api/availabilities/[id].ts b/pages/api/availabilities/[id].ts
index bdb1215f742..546fbe0ce1e 100644
--- a/pages/api/availabilities/[id].ts
+++ b/pages/api/availabilities/[id].ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { AvailabilityResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import { schemaAvailabilityBodyParams, schemaAvailabilityPublic } from "@lib/validations/availability";
import {
schemaQueryIdParseInt,
@@ -97,7 +96,7 @@ export async function availabilityById(req: NextApiRequest, res: NextApiResponse
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaAvailabilityBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
const data = await prisma.availability.findMany({ where: { userId } });
const availabiltiesIds = data.map((availability) => availability.id);
if (availabiltiesIds.includes(safeQuery.data.id)) {
diff --git a/pages/api/availabilities/index.ts b/pages/api/availabilities/index.ts
index 63ae75db493..a6310059f75 100644
--- a/pages/api/availabilities/index.ts
+++ b/pages/api/availabilities/index.ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { AvailabilityResponse, AvailabilitiesResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import { schemaAvailabilityBodyParams, schemaAvailabilityPublic } from "@lib/validations/availability";
/**
@@ -47,7 +46,7 @@ async function createOrlistAllAvailabilities(
res: NextApiResponse<AvailabilitiesResponse | AvailabilityResponse>
) {
const { method } = req;
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
if (method === "GET") {
const data = await prisma.availability.findMany({ where: { userId } });
diff --git a/pages/api/booking-references/[id].ts b/pages/api/booking-references/[id].ts
index 9a1b40089b6..1644041b2ff 100644
--- a/pages/api/booking-references/[id].ts
+++ b/pages/api/booking-references/[id].ts
@@ -5,7 +5,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { BookingReferenceResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import {
schemaBookingReferenceBodyParams,
schemaBookingReferencePublic,
@@ -98,7 +97,7 @@ export async function bookingReferenceById(
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaBookingReferenceBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
const userWithBookings = await prisma.user.findUnique({
where: { id: userId },
include: { bookings: true },
diff --git a/pages/api/booking-references/index.ts b/pages/api/booking-references/index.ts
index 9ceedeed300..03bc7005962 100644
--- a/pages/api/booking-references/index.ts
+++ b/pages/api/booking-references/index.ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { BookingReferenceResponse, BookingReferencesResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import {
schemaBookingReferenceBodyParams,
schemaBookingReferencePublic,
@@ -46,7 +45,7 @@ async function createOrlistAllBookingReferences(
res: NextApiResponse<BookingReferencesResponse | BookingReferenceResponse>
) {
const { method } = req;
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
const userWithBookings = await prisma.user.findUnique({
where: { id: userId },
include: { bookings: true },
@@ -72,7 +71,7 @@ async function createOrlistAllBookingReferences(
}
// const booking_reference = schemaBookingReferencePublic.parse(data);
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
const userWithBookings = await prisma.user.findUnique({
where: { id: userId },
include: { bookings: true },
diff --git a/pages/api/bookings/[id].ts b/pages/api/bookings/[id].ts
index af6a379158c..f40ae3ccbdd 100644
--- a/pages/api/bookings/[id].ts
+++ b/pages/api/bookings/[id].ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { BookingResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import { schemaBookingBodyParams, schemaBookingPublic } from "@lib/validations/booking";
import {
schemaQueryIdParseInt,
@@ -91,7 +90,7 @@ export async function bookingById(req: NextApiRequest, res: NextApiResponse<Book
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaBookingBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
const userWithBookings = await prisma.user.findUnique({
where: { id: userId },
include: { bookings: true },
diff --git a/pages/api/bookings/index.ts b/pages/api/bookings/index.ts
index 107236118dc..9512847ea1e 100644
--- a/pages/api/bookings/index.ts
+++ b/pages/api/bookings/index.ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { BookingResponse, BookingsResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import { schemaBookingBodyParams, schemaBookingPublic, withValidBooking } from "@lib/validations/booking";
/**
@@ -43,7 +42,7 @@ async function createOrlistAllBookings(
res: NextApiResponse<BookingsResponse | BookingResponse>
) {
const { method } = req;
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
if (method === "GET") {
const data = await prisma.booking.findMany({ where: { userId } });
diff --git a/pages/api/daily-event-references/[id].ts b/pages/api/daily-event-references/[id].ts
index 089e21610bd..993e47ed57a 100644
--- a/pages/api/daily-event-references/[id].ts
+++ b/pages/api/daily-event-references/[id].ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { DailyEventReferenceResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import {
schemaDailyEventReferenceBodyParams,
schemaDailyEventReferencePublic,
@@ -97,7 +96,7 @@ export async function dailyEventReferenceById(
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaDailyEventReferenceBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
const userBookings = await prisma.booking.findMany({ where: { userId } });
const userBookingIds = userBookings.map((booking) => booking.id);
const userBookingDailyEventReferences = await prisma.dailyEventReference.findMany({
diff --git a/pages/api/daily-event-references/index.ts b/pages/api/daily-event-references/index.ts
index 8b00334b1ea..7b216d0040c 100644
--- a/pages/api/daily-event-references/index.ts
+++ b/pages/api/daily-event-references/index.ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { DailyEventReferenceResponse, DailyEventReferencesResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import {
schemaDailyEventReferenceBodyParams,
schemaDailyEventReferencePublic,
@@ -46,7 +45,7 @@ async function createOrlistAllDailyEventReferences(
res: NextApiResponse<DailyEventReferencesResponse | DailyEventReferenceResponse>
) {
const { method } = req;
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
const userBookings = await prisma.booking.findMany({ where: { userId } });
const userBookingIds = userBookings.map((booking) => booking.id);
diff --git a/pages/api/destination-calendars/[id].ts b/pages/api/destination-calendars/[id].ts
index 62eb85810cd..579ba834827 100644
--- a/pages/api/destination-calendars/[id].ts
+++ b/pages/api/destination-calendars/[id].ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { DestinationCalendarResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import {
schemaDestinationCalendarBodyParams,
schemaDestinationCalendarPublic,
@@ -97,7 +96,7 @@ export async function destionationCalendarById(
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaDestinationCalendarBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
const data = await prisma.destinationCalendar.findMany({ where: { userId } });
const userDestinationCalendars = data.map((destinationCalendar) => destinationCalendar.id);
// FIXME: Should we also check ownership of bokingId and eventTypeId to avoid users cross-pollinating other users calendars.
diff --git a/pages/api/destination-calendars/index.ts b/pages/api/destination-calendars/index.ts
index 2b904dbc93d..b3bdcaab577 100644
--- a/pages/api/destination-calendars/index.ts
+++ b/pages/api/destination-calendars/index.ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { DestinationCalendarResponse, DestinationCalendarsResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import {
schemaDestinationCalendarBodyParams,
schemaDestinationCalendarPublic,
@@ -46,7 +45,7 @@ async function createOrlistAllDestinationCalendars(
res: NextApiResponse<DestinationCalendarsResponse | DestinationCalendarResponse>
) {
const { method } = req;
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
if (method === "GET") {
const data = await prisma.destinationCalendar.findMany({ where: { userId } });
diff --git a/pages/api/event-type-custom-inputs/[id].ts b/pages/api/event-type-custom-inputs/[id].ts
index 5a004363611..5ff11ff884a 100644
--- a/pages/api/event-type-custom-inputs/[id].ts
+++ b/pages/api/event-type-custom-inputs/[id].ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { EventTypeCustomInputResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import {
schemaEventTypeCustomInputBodyParams,
schemaEventTypeCustomInputPublic,
@@ -94,7 +93,7 @@ async function eventTypeById(req: NextApiRequest, res: NextApiResponse<EventType
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaEventTypeCustomInputBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
const data = await prisma.eventType.findMany({ where: { userId } });
const userEventTypes = data.map((eventType) => eventType.id);
const userEventTypeCustomInputs = await prisma.eventTypeCustomInput.findMany({
diff --git a/pages/api/event-type-custom-inputs/index.ts b/pages/api/event-type-custom-inputs/index.ts
index e6c0c852bf8..82c23f85935 100644
--- a/pages/api/event-type-custom-inputs/index.ts
+++ b/pages/api/event-type-custom-inputs/index.ts
@@ -45,7 +45,7 @@ async function createOrlistAllEventTypeCustomInputs(
res: NextApiResponse<EventTypeCustomInputsResponse | EventTypeCustomInputResponse>
) {
const { method } = req;
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
const data = await prisma.eventType.findMany({ where: { userId } });
const userEventTypes = data.map((eventType) => eventType.id);
// const userEventTypeCustomInputs = await prisma.eventTypeCustomInput.findMany({
diff --git a/pages/api/event-types/[id].ts b/pages/api/event-types/[id].ts
index dc7535cd5ae..80d4f95bb6c 100644
--- a/pages/api/event-types/[id].ts
+++ b/pages/api/event-types/[id].ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { EventTypeResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import { schemaEventTypeBodyParams, schemaEventTypePublic } from "@lib/validations/event-type";
import {
schemaQueryIdParseInt,
@@ -97,7 +96,7 @@ export async function eventTypeById(req: NextApiRequest, res: NextApiResponse<Ev
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaEventTypeBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
const data = await prisma.eventType.findMany({ where: { userId } });
const userEventTypes = data.map((eventType) => eventType.id);
if (userEventTypes.includes(safeQuery.data.id)) {
diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts
index fc6a2a35f73..3135d9e8664 100644
--- a/pages/api/event-types/index.ts
+++ b/pages/api/event-types/index.ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { EventTypeResponse, EventTypesResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import { schemaEventTypeBodyParams, schemaEventTypePublic } from "@lib/validations/event-type";
/**
@@ -47,7 +46,7 @@ async function createOrlistAllEventTypes(
res: NextApiResponse<EventTypesResponse | EventTypeResponse>
) {
const { method } = req;
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
if (method === "GET") {
const data = await prisma.eventType.findMany({ where: { userId } });
diff --git a/pages/api/memberships/[id].ts b/pages/api/memberships/[id].ts
index df62f891072..4c90122f707 100644
--- a/pages/api/memberships/[id].ts
+++ b/pages/api/memberships/[id].ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { MembershipResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import { schemaMembershipBodyParams, schemaMembershipPublic } from "@lib/validations/membership";
import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString";
@@ -108,7 +107,7 @@ export async function membershipById(req: NextApiRequest, res: NextApiResponse<M
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
// This is how we set the userId and teamId in the query for managing compoundId.
const [paramUserId, teamId] = safeQuery.data.id.split("_");
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
if (parseInt(paramUserId) === userId) {
switch (method) {
case "GET":
diff --git a/pages/api/memberships/index.ts b/pages/api/memberships/index.ts
index a7a109da2d4..6402ac8ca4e 100644
--- a/pages/api/memberships/index.ts
+++ b/pages/api/memberships/index.ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { MembershipResponse, MembershipsResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import { schemaMembershipBodyParams, schemaMembershipPublic } from "@lib/validations/membership";
/**
@@ -43,7 +42,7 @@ async function createOrlistAllMemberships(
res: NextApiResponse<MembershipsResponse | MembershipResponse>
) {
const { method } = req;
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
if (method === "GET") {
const data = await prisma.membership.findMany({ where: { userId } });
const memberships = data.map((membership) => schemaMembershipPublic.parse(membership));
diff --git a/pages/api/payments/[id].ts b/pages/api/payments/[id].ts
index 295803ca76e..9d7d28a184d 100644
--- a/pages/api/payments/[id].ts
+++ b/pages/api/payments/[id].ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { PaymentResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import { schemaPaymentPublic } from "@lib/validations/payment";
import {
schemaQueryIdParseInt,
@@ -38,7 +37,7 @@ import {
export async function paymentById(req: NextApiRequest, res: NextApiResponse<PaymentResponse>) {
const { method, query } = req;
const safeQuery = schemaQueryIdParseInt.safeParse(query);
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
if (safeQuery.success && method === "GET") {
const userWithBookings = await prisma.user.findUnique({
diff --git a/pages/api/payments/index.ts b/pages/api/payments/index.ts
index bb2c132c0cf..827bd683406 100644
--- a/pages/api/payments/index.ts
+++ b/pages/api/payments/index.ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { PaymentsResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import { schemaPaymentPublic } from "@lib/validations/payment";
/**
@@ -24,8 +23,8 @@ import { schemaPaymentPublic } from "@lib/validations/payment";
* 404:
* description: No payments were found
*/
-async function allPayments(_: NextApiRequest, res: NextApiResponse<PaymentsResponse>) {
- const userId = getCalcomUserId(res);
+async function allPayments(req: NextApiRequest, res: NextApiResponse<PaymentsResponse>) {
+ const userId = req.userId;
const userWithBookings = await prisma.user.findUnique({
where: { id: userId },
diff --git a/pages/api/schedules/[id].ts b/pages/api/schedules/[id].ts
index 1b46e622694..e0b83f106bf 100644
--- a/pages/api/schedules/[id].ts
+++ b/pages/api/schedules/[id].ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { ScheduleResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import { schemaScheduleBodyParams, schemaSchedulePublic } from "@lib/validations/schedule";
import {
schemaQueryIdParseInt,
@@ -91,7 +90,7 @@ export async function scheduleById(req: NextApiRequest, res: NextApiResponse<Sch
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaScheduleBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
const userSchedules = await prisma.schedule.findMany({ where: { userId } });
const userScheduleIds = userSchedules.map((schedule) => schedule.id);
if (userScheduleIds.includes(safeQuery.data.id)) {
diff --git a/pages/api/schedules/index.ts b/pages/api/schedules/index.ts
index cb4eeaeb9d7..bbdd1c8dbcf 100644
--- a/pages/api/schedules/index.ts
+++ b/pages/api/schedules/index.ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { ScheduleResponse, SchedulesResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import { schemaScheduleBodyParams, schemaSchedulePublic, withValidSchedule } from "@lib/validations/schedule";
/**
@@ -43,7 +42,7 @@ async function createOrlistAllSchedules(
res: NextApiResponse<SchedulesResponse | ScheduleResponse>
) {
const { method } = req;
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
if (method === "GET") {
const data = await prisma.schedule.findMany({ where: { userId } });
diff --git a/pages/api/selected-calendars/[id].ts b/pages/api/selected-calendars/[id].ts
index 69cd9c059e5..c2febd9c475 100644
--- a/pages/api/selected-calendars/[id].ts
+++ b/pages/api/selected-calendars/[id].ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { SelectedCalendarResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import {
schemaSelectedCalendarBodyParams,
schemaSelectedCalendarPublic,
@@ -132,7 +131,7 @@ export async function selectedCalendarById(
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
// This is how we set the userId and externalId in the query for managing compoundId.
const [paramUserId, integration, externalId] = safeQuery.data.id.split("_");
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
if (userId === parseInt(paramUserId)) {
switch (method) {
case "GET":
diff --git a/pages/api/selected-calendars/index.ts b/pages/api/selected-calendars/index.ts
index cb12a5dac7a..0ccde36943f 100644
--- a/pages/api/selected-calendars/index.ts
+++ b/pages/api/selected-calendars/index.ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { SelectedCalendarResponse, SelectedCalendarsResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import {
schemaSelectedCalendarBodyParams,
schemaSelectedCalendarPublic,
@@ -46,7 +45,7 @@ async function createOrlistAllSelectedCalendars(
res: NextApiResponse<SelectedCalendarsResponse | SelectedCalendarResponse>
) {
const { method } = req;
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
if (method === "GET") {
const data = await prisma.selectedCalendar.findMany({ where: { userId } });
diff --git a/pages/api/teams/[id].ts b/pages/api/teams/[id].ts
index de14a27c3d9..69a3a7091f9 100644
--- a/pages/api/teams/[id].ts
+++ b/pages/api/teams/[id].ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { TeamResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import {
schemaQueryIdParseInt,
withValidQueryIdTransformParseInt,
@@ -91,7 +90,7 @@ export async function teamById(req: NextApiRequest, res: NextApiResponse<TeamRes
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaTeamBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
const userWithMemberships = await prisma.membership.findMany({
where: { userId: userId },
});
diff --git a/pages/api/teams/index.ts b/pages/api/teams/index.ts
index a480bff97a1..045fc25461c 100644
--- a/pages/api/teams/index.ts
+++ b/pages/api/teams/index.ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { TeamResponse, TeamsResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import { schemaMembershipPublic } from "@lib/validations/membership";
import { schemaTeamBodyParams, schemaTeamPublic, withValidTeam } from "@lib/validations/team";
@@ -41,7 +40,7 @@ import { schemaTeamBodyParams, schemaTeamPublic, withValidTeam } from "@lib/vali
*/
async function createOrlistAllTeams(req: NextApiRequest, res: NextApiResponse<TeamsResponse | TeamResponse>) {
const { method } = req;
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
if (method === "GET") {
const userWithMemberships = await prisma.membership.findMany({
where: { userId: userId },
diff --git a/pages/api/users/[id].ts b/pages/api/users/[id].ts
index 5beaf442df8..6dd4eb5f636 100644
--- a/pages/api/users/[id].ts
+++ b/pages/api/users/[id].ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import type { UserResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import {
schemaQueryIdParseInt,
withValidQueryIdTransformParseInt,
@@ -91,7 +90,7 @@ export async function userById(req: NextApiRequest, res: NextApiResponse<UserRes
const safeQuery = schemaQueryIdParseInt.safeParse(query);
const safeBody = schemaUserBodyParams.safeParse(body);
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
if (safeQuery.data.id === userId) {
switch (method) {
case "GET":
diff --git a/pages/api/users/index.ts b/pages/api/users/index.ts
index 84c2e7ec579..73f2a46eb6a 100644
--- a/pages/api/users/index.ts
+++ b/pages/api/users/index.ts
@@ -4,7 +4,6 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { UsersResponse } from "@lib/types";
-import { getCalcomUserId } from "@lib/utils/getCalcomUserId";
import { schemaUserPublic } from "@lib/validations/user";
/**
@@ -25,7 +24,7 @@ import { schemaUserPublic } from "@lib/validations/user";
* description: No users were found
*/
async function allUsers(req: NextApiRequest, res: NextApiResponse<UsersResponse>) {
- const userId = getCalcomUserId(res);
+ const userId = req.userId;
const data = await prisma.user.findMany({
where: {
id: userId,
diff --git a/tsconfig.json b/tsconfig.json
index 5acb222ba65..4943d154a61 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,23 +1,19 @@
{
- "extends": "@calcom/tsconfig/base.json",
- "exclude": ["node_modules", "templates"],
+ "extends": "@calcom/tsconfig/nextjs.json",
"compilerOptions": {
- "strictNullChecks": true,
"baseUrl": ".",
-
- "target": "es5",
- "lib": ["dom", "dom.iterable", "esnext"],
- "allowJs": true,
- "noEmit": true,
- "incremental": true,
- "module": "esnext",
- "resolveJsonModule": true,
- "jsx": "preserve",
"paths": {
"@api/*": ["pages/api/*"],
"@lib/*": ["lib/*"],
"@/*": ["*"]
}
},
- "include": ["./**/*.ts*"]
+ "include": [
+ "next-env.d.ts",
+ "../../packages/types/*.d.ts",
+ "../../packages/types/next-auth.d.ts",
+ "**/*.ts",
+ "**/*.tsx"
+ ],
+ "exclude": ["node_modules", "templates"]
}