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.ts index da7a203ac3..2e89578324 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/o import { 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 { + 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 { + async getOAuthClients(@GetUser() user: UserWithProfile): Promise { + 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.ts index 2aaca81594..56b0601c93 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>(endpoint.toString()).then((res) => { + return http?.get>(pathname).then((res) => { if (res.data.status === SUCCESS_STATUS) { return (res.data as ApiSuccessResponse).data; } diff --git a/packages/platform/atoms/hooks/event-types/useEventTypesPublic.ts b/packages/platform/atoms/hooks/event-types/useEventTypesPublic.ts index 358a2d717d..a67f76b6ec 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>(endpoint.toString()).then((res) => { + return http?.get>(pathname).then((res) => { if (res.data.status === SUCCESS_STATUS) { return (res.data as ApiSuccessResponse).data; } diff --git a/packages/platform/atoms/hooks/event-types/useGetEventTypeById.ts b/packages/platform/atoms/hooks/event-types/useGetEventTypeById.ts index c950eae553..9d7bb19139 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>(endpoint.toString()).then((res) => { + return http?.get>(pathname).then((res) => { if (res.data.status === SUCCESS_STATUS) { return (res.data as ApiSuccessResponse).data; } diff --git a/packages/platform/atoms/hooks/useClientSchedule.ts b/packages/platform/atoms/hooks/useClientSchedule.ts index b099e25b14..edc950942b 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>(endpoint.toString()).then((res) => { + return http.get>(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.ts index b177849d30..0322dcbb31 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, 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.ts index 8cefb1b77e..b2a9089989 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>["bookingInfo"]>>(endpoint.toString()) + .get>["bookingInfo"]>>(pathname) .then((res) => { if (res.data.status === SUCCESS_STATUS) { return (res.data as ApiSuccessResponse>["bookingInfo"]>) diff --git a/packages/platform/atoms/hooks/useGetBookingForReschedule.ts b/packages/platform/atoms/hooks/useGetBookingForReschedule.ts index 4a93fbbda0..b2d7f364f1 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>>>(endpoint.toString()) + .get>>>(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.ts index dfff9c3d93..afa8578f3d 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>>>(endpoint.toString(), { + .get>>>(pathname, { params: input, }) .then((res) => { if (res.data.status === SUCCESS_STATUS) { - return res.data.data; + return (res.data as ApiSuccessResponse>>).data; } throw new Error(res.data.error.message); }); diff --git a/packages/platform/atoms/hooks/useGetCityTimezones.ts b/packages/platform/atoms/hooks/useGetCityTimezones.ts index e206860329..70996b2916 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.ts index 663026d58e..c0e9f21b5b 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>(endpoint.toString()).then((res) => { + return http?.get>(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.ts index c0d44f597c..4e07cc834e 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, 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>(endpoint.toString(), data).then((res) => { + return http.patch>(pathname, data).then((res) => { return res.data; }); }, diff --git a/packages/platform/atoms/hooks/useUpdateUserTimezone.ts b/packages/platform/atoms/hooks/useUpdateUserTimezone.ts index 597d7c4d6a..64531912c5 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, 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; }