Scheduling infrastructure for absolutely everyone.
fix: urls, gcal check, oauth client controller (#14335)
Morgan1fff6428606f
diff --git a/apps/api/v2/src/modules/oauth-clients/controllers/oauth-clients/oauth-clients.controller.ts b/apps/api/v2/src/modules/oauth-clients/controllers/oauth-clients/oauth-clients.controller.tsindex da7a203ac37..2e895783240 100644--- a/apps/api/v2/src/modules/oauth-clients/controllers/oauth-clients/oauth-clients.controller.ts+++ b/apps/api/v2/src/modules/oauth-clients/controllers/oauth-clients/oauth-clients.controller.ts@@ -8,6 +8,7 @@ import { GetOAuthClientResponseDto } from "@/modules/oauth-clients/controllers/oimport { GetOAuthClientsResponseDto } from "@/modules/oauth-clients/controllers/oauth-clients/responses/GetOAuthClientsResponse.dto";import { UpdateOAuthClientInput } from "@/modules/oauth-clients/inputs/update-oauth-client.input";import { OAuthClientRepository } from "@/modules/oauth-clients/oauth-client.repository";+import { UserWithProfile } from "@/modules/users/users.repository";import {Body,Controller,@@ -57,9 +58,10 @@ export class OAuthClientsController {type: CreateOAuthClientResponseDto,})async createOAuthClient(- @GetUser("organizationId") organizationId: number,+ @GetUser() user: UserWithProfile,@Body() body: CreateOAuthClientInput): Promise<CreateOAuthClientResponseDto> {+ const organizationId = (user.movedToProfile?.organizationId ?? user.organizationId) as number;this.logger.log(`For organisation ${organizationId} creating OAuth Client with data: ${JSON.stringify(body)}`);@@ -77,9 +79,9 @@ export class OAuthClientsController {@HttpCode(HttpStatus.OK)@Roles([MembershipRole.ADMIN, MembershipRole.OWNER, MembershipRole.MEMBER])@DocsOperation({ description: AUTH_DOCUMENTATION })- async getOAuthClients(- @GetUser("organizationId") organizationId: number- ): Promise<GetOAuthClientsResponseDto> {+ async getOAuthClients(@GetUser() user: UserWithProfile): Promise<GetOAuthClientsResponseDto> {+ const organizationId = (user.movedToProfile?.organizationId ?? user.organizationId) as number;+const clients = await this.oauthClientRepository.getOrganizationOAuthClients(organizationId);return { status: SUCCESS_STATUS, data: clients };}diff --git a/packages/platform/atoms/hooks/event-types/useEventTypesPrivate.ts b/packages/platform/atoms/hooks/event-types/useEventTypesPrivate.tsindex 2aaca815941..56b0601c93a 100644--- a/packages/platform/atoms/hooks/event-types/useEventTypesPrivate.ts+++ b/packages/platform/atoms/hooks/event-types/useEventTypesPrivate.ts@@ -1,6 +1,6 @@import { useQuery } from "@tanstack/react-query";-import { BASE_URL, API_VERSION, V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";+import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";import type { EventTypesByViewer } from "@calcom/platform-libraries";import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";@@ -8,14 +8,12 @@ import http from "../../lib/http";export const QUERY_KEY = "get-private-events";export const useEventTypesPrivate = () => {- const endpoint = new URL(BASE_URL);-- endpoint.pathname = `api/${API_VERSION}/${V2_ENDPOINTS.eventTypes}`;+ const pathname = `/${V2_ENDPOINTS.eventTypes}`;return useQuery({queryKey: [QUERY_KEY],queryFn: () => {- return http?.get<ApiResponse<EventTypesByViewer>>(endpoint.toString()).then((res) => {+ return http?.get<ApiResponse<EventTypesByViewer>>(pathname).then((res) => {if (res.data.status === SUCCESS_STATUS) {return (res.data as ApiSuccessResponse<EventTypesByViewer>).data;}diff --git a/packages/platform/atoms/hooks/event-types/useEventTypesPublic.ts b/packages/platform/atoms/hooks/event-types/useEventTypesPublic.tsindex 358a2d717de..a67f76b6ec3 100644--- a/packages/platform/atoms/hooks/event-types/useEventTypesPublic.ts+++ b/packages/platform/atoms/hooks/event-types/useEventTypesPublic.ts@@ -1,6 +1,6 @@import { useQuery } from "@tanstack/react-query";-import { BASE_URL, API_VERSION, V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";+import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";import type { EventTypesPublic } from "@calcom/platform-libraries";import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";@@ -8,14 +8,12 @@ import http from "../../lib/http";export const QUERY_KEY = "get-public-events";export const useEventTypesPublic = (username: string) => {- const endpoint = new URL(BASE_URL);-- endpoint.pathname = `api/${API_VERSION}/${V2_ENDPOINTS.eventTypes}/${username}/public`;+ const pathname = `/${V2_ENDPOINTS.eventTypes}/${username}/public`;return useQuery({queryKey: [QUERY_KEY, username],queryFn: () => {- return http?.get<ApiResponse<EventTypesPublic>>(endpoint.toString()).then((res) => {+ return http?.get<ApiResponse<EventTypesPublic>>(pathname).then((res) => {if (res.data.status === SUCCESS_STATUS) {return (res.data as ApiSuccessResponse<EventTypesPublic>).data;}diff --git a/packages/platform/atoms/hooks/event-types/useGetEventTypeById.ts b/packages/platform/atoms/hooks/event-types/useGetEventTypeById.tsindex c950eae553b..9d7bb19139d 100644--- a/packages/platform/atoms/hooks/event-types/useGetEventTypeById.ts+++ b/packages/platform/atoms/hooks/event-types/useGetEventTypeById.ts@@ -1,6 +1,6 @@import { useQuery } from "@tanstack/react-query";-import { BASE_URL, API_VERSION, V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";+import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";import type { EventType as AtomEventType } from "@calcom/platform-libraries";import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";@@ -8,15 +8,12 @@ import http from "../../lib/http";export const QUERY_KEY = "get-event-by-id";export const useGetEventTypeById = (id: number | null) => {- const endpoint = new URL(BASE_URL);-- endpoint.pathname = `api/${API_VERSION}/${V2_ENDPOINTS.eventTypes}/${id}`;- endpoint.searchParams.set("for", "atom");+ const pathname = `/${V2_ENDPOINTS.eventTypes}/${id}?for=atom`;return useQuery({queryKey: [QUERY_KEY, id],queryFn: () => {- return http?.get<ApiResponse<AtomEventType>>(endpoint.toString()).then((res) => {+ return http?.get<ApiResponse<AtomEventType>>(pathname).then((res) => {if (res.data.status === SUCCESS_STATUS) {return (res.data as ApiSuccessResponse<AtomEventType>).data;}diff --git a/packages/platform/atoms/hooks/useClientSchedule.ts b/packages/platform/atoms/hooks/useClientSchedule.tsindex b099e25b14f..edc950942bb 100644--- a/packages/platform/atoms/hooks/useClientSchedule.ts+++ b/packages/platform/atoms/hooks/useClientSchedule.ts@@ -1,6 +1,6 @@import { useQuery } from "@tanstack/react-query";-import { BASE_URL, API_VERSION, V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";+import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";import type { ScheduleWithAvailabilitiesForWeb } from "@calcom/platform-libraries";import type { ApiResponse } from "@calcom/platform-types";@@ -9,18 +9,14 @@ import http from "../lib/http";export const QUERY_KEY = "user-schedule";const useClientSchedule = (id?: string) => {- const endpoint = new URL(BASE_URL);-- endpoint.pathname = id- ? `api/${API_VERSION}/${V2_ENDPOINTS.availability}/${id}`- : `api/${API_VERSION}/${V2_ENDPOINTS.availability}/default`;-- endpoint.searchParams.set("for", "atom");+ const pathname = id+ ? `/${V2_ENDPOINTS.availability}/${id}?for=atom`+ : `/${V2_ENDPOINTS.availability}/default?for=atom`;const { isLoading, error, data } = useQuery({queryKey: [QUERY_KEY, id],queryFn: () => {- return http.get<ApiResponse<ScheduleWithAvailabilitiesForWeb>>(endpoint.toString()).then((res) => {+ return http.get<ApiResponse<ScheduleWithAvailabilitiesForWeb>>(pathname).then((res) => {if (res.data.status === SUCCESS_STATUS) {return res.data;}diff --git a/packages/platform/atoms/hooks/useDeleteSchedule.ts b/packages/platform/atoms/hooks/useDeleteSchedule.tsindex b177849d304..0322dcbb31d 100644--- a/packages/platform/atoms/hooks/useDeleteSchedule.ts+++ b/packages/platform/atoms/hooks/useDeleteSchedule.ts@@ -1,7 +1,7 @@import { useMutation, useQueryClient } from "@tanstack/react-query";import { SUCCESS_STATUS } from "@calcom/platform-constants";-import { BASE_URL, API_VERSION, V2_ENDPOINTS } from "@calcom/platform-constants";+import { V2_ENDPOINTS } from "@calcom/platform-constants";import type { ApiResponse, ApiErrorResponse } from "@calcom/platform-types";import http from "../lib/http";@@ -26,16 +26,14 @@ const useDeleteSchedule = (},}) => {- const endpoint = new URL(BASE_URL);const queryClient = useQueryClient();const mutation = useMutation<ApiResponse<undefined>, unknown, DeleteScheduleInput>({mutationFn: (data) => {const { id } = data;- endpoint.pathname = `api/${API_VERSION}/${V2_ENDPOINTS.availability}/${id}`;- endpoint.searchParams.set("for", "atom");+ const pathname = `/${V2_ENDPOINTS.availability}/${id}?for=atom`;- return http?.delete(endpoint.toString()).then((res) => res.data);+ return http?.delete(pathname).then((res) => res.data);},onSuccess: (data) => {if (data.status === SUCCESS_STATUS) {diff --git a/packages/platform/atoms/hooks/useGetBooking.ts b/packages/platform/atoms/hooks/useGetBooking.tsindex 8cefb1b77e3..b2a90899893 100644--- a/packages/platform/atoms/hooks/useGetBooking.ts+++ b/packages/platform/atoms/hooks/useGetBooking.ts@@ -1,6 +1,6 @@import { useQuery } from "@tanstack/react-query";-import { BASE_URL, API_VERSION, V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";+import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";import type { getBookingInfo } from "@calcom/platform-libraries";import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";@@ -9,15 +9,13 @@ import http from "../lib/http";export const QUERY_KEY = "user-booking";export const useGetBooking = (uid = "") => {- const endpoint = new URL(BASE_URL);-- endpoint.pathname = `api/${API_VERSION}/${V2_ENDPOINTS.bookings}/${uid}`;+ const pathname = `/${V2_ENDPOINTS.bookings}/${uid}`;const bookingQuery = useQuery({queryKey: [QUERY_KEY, uid],queryFn: () => {return http- .get<ApiResponse<Awaited<ReturnType<typeof getBookingInfo>>["bookingInfo"]>>(endpoint.toString())+ .get<ApiResponse<Awaited<ReturnType<typeof getBookingInfo>>["bookingInfo"]>>(pathname).then((res) => {if (res.data.status === SUCCESS_STATUS) {return (res.data as ApiSuccessResponse<Awaited<ReturnType<typeof getBookingInfo>>["bookingInfo"]>)diff --git a/packages/platform/atoms/hooks/useGetBookingForReschedule.ts b/packages/platform/atoms/hooks/useGetBookingForReschedule.tsindex 4a93fbbda01..b2d7f364f1a 100644--- a/packages/platform/atoms/hooks/useGetBookingForReschedule.ts+++ b/packages/platform/atoms/hooks/useGetBookingForReschedule.ts@@ -1,6 +1,6 @@import { useQuery } from "@tanstack/react-query";-import { BASE_URL, API_VERSION, V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";+import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";import type { getBookingForReschedule } from "@calcom/platform-libraries";import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";@@ -24,15 +24,13 @@ export const useGetBookingForReschedule = (uid: "",}) => {- const endpoint = new URL(BASE_URL);-- endpoint.pathname = `api/${API_VERSION}/${V2_ENDPOINTS.bookings}/${props.uid}/reschedule`;+ const pathname = `/${V2_ENDPOINTS.bookings}/${props.uid}/reschedule`;const bookingQuery = useQuery({queryKey: [QUERY_KEY, props.uid],queryFn: () => {return http- .get<ApiResponse<Awaited<ReturnType<typeof getBookingForReschedule>>>>(endpoint.toString())+ .get<ApiResponse<Awaited<ReturnType<typeof getBookingForReschedule>>>>(pathname).then((res) => {if (res.data.status === SUCCESS_STATUS) {props.onSuccess?.(diff --git a/packages/platform/atoms/hooks/useGetBookings.ts b/packages/platform/atoms/hooks/useGetBookings.tsindex dfff9c3d93d..afa8578f3dc 100644--- a/packages/platform/atoms/hooks/useGetBookings.ts+++ b/packages/platform/atoms/hooks/useGetBookings.ts@@ -1,8 +1,8 @@import { useQuery } from "@tanstack/react-query";-import { BASE_URL, SUCCESS_STATUS, API_VERSION, V2_ENDPOINTS } from "@calcom/platform-constants";+import { SUCCESS_STATUS, V2_ENDPOINTS } from "@calcom/platform-constants";import type { getAllUserBookings } from "@calcom/platform-libraries";-import type { ApiResponse } from "@calcom/platform-types";+import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";import type { GetBookingsInput } from "@calcom/platform-types/bookings";import http from "../lib/http";@@ -10,20 +10,18 @@ import http from "../lib/http";export const QUERY_KEY = "user-bookings";export const useGetBookings = (input: GetBookingsInput) => {- const endpoint = new URL(BASE_URL);-- endpoint.pathname = `api/${API_VERSION}/${V2_ENDPOINTS.bookings}`;+ const pathname = `/${V2_ENDPOINTS.bookings}`;const bookingsQuery = useQuery({queryKey: [QUERY_KEY, input?.limit ?? 50, input?.cursor ?? 0, input?.filters?.status ?? "upcoming"],queryFn: () => {return http- .get<ApiResponse<Awaited<ReturnType<typeof getAllUserBookings>>>>(endpoint.toString(), {+ .get<ApiResponse<Awaited<ReturnType<typeof getAllUserBookings>>>>(pathname, {params: input,}).then((res) => {if (res.data.status === SUCCESS_STATUS) {- return res.data.data;+ return (res.data as ApiSuccessResponse<Awaited<ReturnType<typeof getAllUserBookings>>>).data;}throw new Error(res.data.error.message);});diff --git a/packages/platform/atoms/hooks/useGetCityTimezones.ts b/packages/platform/atoms/hooks/useGetCityTimezones.tsindex e2068603296..70996b29168 100644--- a/packages/platform/atoms/hooks/useGetCityTimezones.ts+++ b/packages/platform/atoms/hooks/useGetCityTimezones.ts@@ -1,18 +1,14 @@import { useQuery } from "@tanstack/react-query";-import { BASE_URL, API_VERSION } from "@calcom/platform-constants";-import http from "../lib/http";const useGetCityTimezones = () => {- const endpoint = new URL(BASE_URL);-- endpoint.pathname = `api/${API_VERSION}/timezones`;+ const pathname = `/timezones`;const { isLoading, data } = useQuery({queryKey: ["city-timezones"],queryFn: () => {- return http?.get(endpoint.toString()).then((res) => res.data);+ return http?.get(pathname).then((res) => res.data);},});diff --git a/packages/platform/atoms/hooks/useMe.ts b/packages/platform/atoms/hooks/useMe.tsindex 663026d58e0..c0e9f21b5ba 100644--- a/packages/platform/atoms/hooks/useMe.ts+++ b/packages/platform/atoms/hooks/useMe.ts@@ -1,20 +1,17 @@import { useQuery } from "@tanstack/react-query";-import { BASE_URL, API_VERSION, V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";+import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";import type { ApiResponse, UserResponse } from "@calcom/platform-types";import http from "../lib/http";export const QUERY_KEY = "get-me";export const useMe = () => {- const endpoint = new URL(BASE_URL);-- endpoint.pathname = `api/${API_VERSION}/${V2_ENDPOINTS.me}`;-+ const pathname = `/${V2_ENDPOINTS.me}`;const me = useQuery({queryKey: [QUERY_KEY],queryFn: () => {- return http?.get<ApiResponse<UserResponse>>(endpoint.toString()).then((res) => {+ return http?.get<ApiResponse<UserResponse>>(pathname).then((res) => {if (res.data.status === SUCCESS_STATUS) {return res.data;}diff --git a/packages/platform/atoms/hooks/useUpdateSchedule.ts b/packages/platform/atoms/hooks/useUpdateSchedule.tsindex c0d44f597c9..4e07cc834e0 100644--- a/packages/platform/atoms/hooks/useUpdateSchedule.ts+++ b/packages/platform/atoms/hooks/useUpdateSchedule.ts@@ -1,7 +1,7 @@import { useMutation, useQueryClient } from "@tanstack/react-query";import { SUCCESS_STATUS } from "@calcom/platform-constants";-import { BASE_URL, API_VERSION, V2_ENDPOINTS } from "@calcom/platform-constants";+import { V2_ENDPOINTS } from "@calcom/platform-constants";import type { UpdateScheduleOutputType } from "@calcom/platform-libraries";import type { ApiResponse, UpdateScheduleInput, ApiErrorResponse } from "@calcom/platform-types";@@ -23,15 +23,13 @@ const useUpdateSchedule = (},}) => {- const endpoint = new URL(BASE_URL);const queryClient = useQueryClient();const mutation = useMutation<ApiResponse<UpdateScheduleOutputType>, unknown, UpdateScheduleInput>({mutationFn: (data) => {- endpoint.pathname = `api/${API_VERSION}/${V2_ENDPOINTS.availability}/${data.scheduleId}`;- endpoint.searchParams.set("for", "atom");+ const pathname = `/${V2_ENDPOINTS.availability}/${data.scheduleId}?for=atom`;- return http.patch<ApiResponse<UpdateScheduleOutputType>>(endpoint.toString(), data).then((res) => {+ return http.patch<ApiResponse<UpdateScheduleOutputType>>(pathname, data).then((res) => {return res.data;});},diff --git a/packages/platform/atoms/hooks/useUpdateUserTimezone.ts b/packages/platform/atoms/hooks/useUpdateUserTimezone.tsindex 597d7c4d6ab..64531912c55 100644--- a/packages/platform/atoms/hooks/useUpdateUserTimezone.ts+++ b/packages/platform/atoms/hooks/useUpdateUserTimezone.ts@@ -1,6 +1,6 @@import { useMutation } from "@tanstack/react-query";-import { BASE_URL, API_VERSION, V2_ENDPOINTS } from "@calcom/platform-constants";+import { V2_ENDPOINTS } from "@calcom/platform-constants";import { SUCCESS_STATUS } from "@calcom/platform-constants";import type { ApiResponse, UserResponse } from "@calcom/platform-types";@@ -11,15 +11,13 @@ type updateTimezoneInput = {};export const useUpdateUserTimezone = () => {- const endpoint = new URL(BASE_URL);-- endpoint.pathname = `api/${API_VERSION}/${V2_ENDPOINTS.me}`;+ const pathname = `/${V2_ENDPOINTS.me}`;const mutation = useMutation<ApiResponse<UserResponse>, unknown, updateTimezoneInput>({mutationFn: (data) => {const { timeZone } = data;- return http?.patch(endpoint.toString(), { timeZone }).then((res) => {+ return http?.patch(pathname, { timeZone }).then((res) => {if (res.data.status === SUCCESS_STATUS) {return res.data;}