fix: urls, gcal check, oauth client controller (#14335)
* fix: urls, gcal check, oauth client controller * fixup! fix: urls, gcal check, oauth client controller
This commit is contained in:
+6
-4
@@ -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<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 };
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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"]>)
|
||||
|
||||
@@ -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?.(
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
},
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user