Refactoring and fixes
This commit is contained in:
1 parent
9239b27216
commit
be3bcf2bf0
35 files changed
+64
-107
No files matched your search
@@ -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 },
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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 } });
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -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 } });
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 } });
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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 } });
|
||||
|
||||
@@ -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":
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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 } });
|
||||
|
||||
@@ -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":
|
||||
|
||||
@@ -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 } });
|
||||
|
||||
@@ -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 },
|
||||
});
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -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":
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user