problem with objectId with bson and such in models but fixed it and nice rendering everything now
This commit is contained in:
@@ -2,6 +2,7 @@ import { $authTokens, $searchQuery } from "./recoil";
|
||||
import axios, { AxiosResponse } from "axios";
|
||||
import { useMutation, useQuery } from "react-query";
|
||||
|
||||
import GetConversationDetailsResponse from "@nirvana/core/responses/getConversationDetails.response";
|
||||
import SearchResponse from "@nirvana/core/responses/search.response";
|
||||
import { User } from "@nirvana/core/models";
|
||||
import { nirvanaApi } from "./nirvanaApi";
|
||||
@@ -11,31 +12,47 @@ import { useRecoilValue } from "recoil";
|
||||
// =========== API
|
||||
export const localHost = "http://localhost:5000/api";
|
||||
|
||||
const getUserDetails = async (
|
||||
accessToken: string,
|
||||
idToken: string
|
||||
): Promise<AxiosResponse<User, any>> => {
|
||||
return await axios.get(localHost + `/users?access_token=${accessToken}`, {
|
||||
headers: { Authorization: idToken },
|
||||
});
|
||||
const getUserDetails = async (accessToken: string, idToken: string) => {
|
||||
const response = await axios.get<User>(
|
||||
localHost + `/users?access_token=${accessToken}`,
|
||||
{
|
||||
headers: { Authorization: idToken },
|
||||
}
|
||||
);
|
||||
|
||||
return response.data;
|
||||
};
|
||||
|
||||
const search = async (
|
||||
idToken: string,
|
||||
searchQuery: string
|
||||
): Promise<AxiosResponse<SearchResponse, any>> => {
|
||||
return await axios.get<SearchResponse>(
|
||||
const search = async (idToken: string, searchQuery: string) => {
|
||||
const response = await axios.get<SearchResponse>(
|
||||
localHost + `/search?query=${searchQuery}`,
|
||||
{
|
||||
headers: { Authorization: idToken },
|
||||
}
|
||||
);
|
||||
|
||||
return response.data;
|
||||
};
|
||||
|
||||
const getConversationDetails = async (
|
||||
idToken: string,
|
||||
otherUserGoogleId: string
|
||||
) => {
|
||||
const response = await axios.get<GetConversationDetailsResponse>(
|
||||
localHost + `/conversations/${otherUserGoogleId}`,
|
||||
{
|
||||
headers: { Authorization: idToken },
|
||||
}
|
||||
);
|
||||
|
||||
return response.data;
|
||||
};
|
||||
|
||||
// ====== QUERIES
|
||||
export enum Querytypes {
|
||||
GET_USER_DETAILS = "GET_USER_DETAILS",
|
||||
GET_SEARCH_RESULTS = "GET_SEARCH_RESULTS",
|
||||
GET_CONVERSATION_DETAILS = "GET_CONVERSATION_DETAILS",
|
||||
}
|
||||
export function useGetUserDetails() {
|
||||
const authTokens = useRecoilValue($authTokens);
|
||||
@@ -61,6 +78,16 @@ export function useSearch() {
|
||||
);
|
||||
}
|
||||
|
||||
export function useConversationDetails(otherUserGoogleId: string) {
|
||||
const authTokens = useRecoilValue($authTokens);
|
||||
|
||||
return useQuery(
|
||||
Querytypes.GET_CONVERSATION_DETAILS + "/" + otherUserGoogleId,
|
||||
() => getConversationDetails(authTokens.idToken, otherUserGoogleId),
|
||||
{ enabled: otherUserGoogleId ? true : false }
|
||||
);
|
||||
}
|
||||
|
||||
// =========== MUTATIONS
|
||||
export function useCreateUser() {
|
||||
return useMutation(nirvanaApi.user.createUser, {
|
||||
|
||||
Reference in New Issue
Block a user