Refactoring and fixes

pull/9078/head
zomars 2022-04-21 19:36:33 -06:00
parent 9239b27216
commit be3bcf2bf0
35 changed files with 64 additions and 107 deletions

View File

@ -1,4 +0,0 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
yarn pre-commit

View File

@ -1 +0,0 @@
module.exports = require("../../packages/config/prettier-preset");

View File

@ -1,3 +0,0 @@
module.exports = {
presets: [["@babel/preset-env", { targets: { node: "current" } }], "@babel/preset-typescript"],
};

View File

@ -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();
};

View File

@ -1,3 +0,0 @@
import { NextApiResponse } from "next";
export const getCalcomUserId = (res: NextApiResponse): number => res.getHeader("x-calcom-user-id") as number;

View File

@ -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",

View File

@ -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 },

View File

@ -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 },

View File

@ -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)) {

View File

@ -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 } });

View File

@ -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 },

View File

@ -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 },

View File

@ -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 },

View File

@ -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 } });

View File

@ -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({

View File

@ -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);

View File

@ -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.

View File

@ -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 } });

View File

@ -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({

View File

@ -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({

View File

@ -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)) {

View File

@ -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 } });

View File

@ -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":

View File

@ -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));

View File

@ -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({

View File

@ -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 },

View File

@ -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)) {

View File

@ -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 } });

View File

@ -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":

View File

@ -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 } });

View File

@ -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 },
});

View File

@ -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 },

View File

@ -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":

View File

@ -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,

View File

@ -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"]
}