fixing things regarding bson error with node and such...now working?

This commit is contained in:
talksik
2022-04-03 09:04:25 -04:00
parent 7205fac3f5
commit 19b90b2196
11 changed files with 248 additions and 41 deletions
@@ -31,3 +31,6 @@ export function useUserSearch(searchQuery: string) {
}
// =========== MUTATIONS
export function useGetDmByUserId() {
return useMutation(ApiCalls.getDmByUserId);
}
@@ -1,5 +1,6 @@
import axios, { AxiosRequestConfig, AxiosResponse, Method } from "axios";
import { Conversation } from "../../../core/models/conversation.model";
import LoginResponse from "../../../core/responses/login.response";
import { User } from "@nirvana/core/models";
import UserDetailsResponse from "../../../core/responses/userDetails.response";
@@ -69,9 +70,18 @@ async function userSearch(searchQuery: string): Promise<UserSearchResponse> {
);
}
async function getDmByUserId(otherUserId: string): Promise<Conversation> {
return await NirvanaApi.fetch(
`/conversations/dm/${otherUserId}`,
"GET",
true
);
}
export const ApiCalls = {
login,
authCheck,
getUserDetails,
userSearch,
getDmByUserId,
};
@@ -8,12 +8,18 @@ import {
} from "@mui/material";
import { Check, Search } from "@mui/icons-material";
import { useEffect, useState } from "react";
import {
useGetDmByUserId,
useGetUserDetails,
useUserSearch,
} from "../../../controller/index";
import { $newConvoPage } from "../../../controller/recoil";
import { ApiCalls } from "../../../controller/nirvanaApi";
import { User } from "@nirvana/core/models/user.model";
import UserRow from "../../../components/User/basicUserDetailsRow";
import toast from "react-hot-toast";
import { useSetRecoilState } from "recoil";
import { useUserSearch } from "../../../controller/index";
export default function NewConvo() {
const setNewPageConvo = useSetRecoilState($newConvoPage);
@@ -21,6 +27,8 @@ export default function NewConvo() {
const [debUserSearchQ, setDebUserSearchQ] = useState<string>("");
const [selectedUsers, setSelectedUsers] = useState<User[]>([]);
const { data: userDetails } = useGetUserDetails();
const {
data,
isLoading: isSearching,
@@ -101,13 +109,36 @@ export default function NewConvo() {
);
}
const createConvo = () => {
const { mutateAsync } = useGetDmByUserId();
const createConvo = async () => {
if (!selectedUsers?.length) {
toast.error("Must select at least one person");
return;
}
// consolidate the user Ids into an array
// make sure that there are no duplicates
console;
// const userIds = selectedUsers.map((selUser) => selUser._id.toString());
// userIds.push(userDetails.user._id.toString());
// IF it's a one on one chat
// check backend with one route if there is an existing conversation
console;
if (selectedUsers?.length === 1) {
let existingConvo;
try {
existingConvo = await mutateAsync(selectedUsers[0]._id.toString());
console.log("there is an existing convo!");
console.log(existingConvo);
} catch (error) {
console.error(error);
} finally {
console.log("done");
}
}
// create a conversation object in db with two members, me and this other person
// IF it's a group convo/room/channel, create a channel with these people
};