diff --git a/backend/src/controller/comment.js b/backend/src/controller/comment.js index e5c034d..13258d9 100644 --- a/backend/src/controller/comment.js +++ b/backend/src/controller/comment.js @@ -27,7 +27,6 @@ export const createComment =async (req,res)=>{ parent:true, }, }) - // console.log("Child Comment = "+newComment.body+" ParentID "+newComment.parentId); return res.status(201).json({ msg:"Successfully Created", newComment:newComment, diff --git a/backend/src/controller/rooms.js b/backend/src/controller/rooms.js index 3e30b3a..a7622f9 100644 --- a/backend/src/controller/rooms.js +++ b/backend/src/controller/rooms.js @@ -485,7 +485,7 @@ export const addUser = async(req,res)=>{ const notification= await tsx.notification.create({ data:{ title:`${room.title}`, - body:`Please Add ${Username} in your Room: ${room.title} Click Here to Accept`, + body:`Please Add Username: "${Username}" in your Private Room: "${room.title}"`, toUser:room.CreatorId, fromUser:userId, } @@ -579,7 +579,7 @@ export const sendJoiningRequest = async(req,res)=>{ const { title } = req.body; const { username } = req.params; // console.log("Sending Room Joining Request = "); - console.log(userID+" "+title+" "+username); + // console.log(userID+" "+title+" "+username); if(!title || !username) { return res.status(404).json({ @@ -605,7 +605,8 @@ export const sendJoiningRequest = async(req,res)=>{ if(!user) return res.status(200).json({ msg:"Please Enter Correct Username" }) - // console.log("Above Room Fetching Block"); + // console.log(user); + // console.log("Above Room Fetching Block "+title); const room = await prisma.rooms.findFirst({ where:{ title, @@ -614,31 +615,32 @@ export const sendJoiningRequest = async(req,res)=>{ UsersEnrolled:true } }); + if(!room)return res.status(404).json({msg:"Room Not Found"}); if(room.CreatorId != userID)return res.status(401).json({msg:"You are not authorised"}); let found =false; - console.log("Above ForEach Bloco"); + // console.log("Above ForEach Bloco"); room.UsersEnrolled.forEach((rooms)=>{ if(rooms.userId === user.userID){ found = true; } }) - console.log("We Have found ",found) + // console.log("We Have found ",found) if(found) { const enrollment = await prisma.enrolledRooms.update({ where:{ - AND:[ - {userId:user.userID}, - {RoomId:room.id} - ] + userId_RoomId: { + userId: user.userID, + RoomId: room.id, + }, }, data:{ joined:true, } }) - + // console.log(enrollment); if(enrollment) { return res.status(200).json({ msg:"User Added Successfully" diff --git a/backend/src/controller/upvotes.js b/backend/src/controller/upvotes.js index ea6dc8a..214ec89 100644 --- a/backend/src/controller/upvotes.js +++ b/backend/src/controller/upvotes.js @@ -80,10 +80,8 @@ export const vote = async (req, res) => { post: true, }, }); - console.log("existing", existingUpvote); if (existingUpvote) { - console.log("upvote exists"); const upvte = await prisma.upvote.update({ where: { @@ -98,7 +96,7 @@ export const vote = async (req, res) => { }); console.log(upvte); - res.status(201).json({ + return res.status(201).json({ msg: "Success", newUpvote: upvte, }); @@ -123,13 +121,13 @@ export const vote = async (req, res) => { post: true, }, }); - res.status(201).json({ + return res.status(201).json({ msg: "created", newUpvote, }); } } catch (error) { - res.status(500).json({ + return res.status(500).json({ msg: "Failed", error, }); diff --git a/backend/src/controller/user.js b/backend/src/controller/user.js index 8950463..b5f0d82 100644 --- a/backend/src/controller/user.js +++ b/backend/src/controller/user.js @@ -281,7 +281,7 @@ const update = async(req,res)=>{ const userId = req.userId; var hashPass = undefined; if(body.password)hashPass = bcrypt.hashSync(body.password, 10); - + console.log(body); try { const user = await prisma.user.update({ where:{ @@ -292,9 +292,10 @@ const update = async(req,res)=>{ username:body.username?body.username:undefined, password:hashPass, codeforces:body.rank?body.rank:undefined, - showCf:body.showCF?body.showCF:undefined + showCf:body?.showCF } }); + console.log(user); res.status(201).json({ msg:"Succesfully Updated", user diff --git a/backend/src/middlewares/verifytoken.js b/backend/src/middlewares/verifytoken.js index b416fd3..861837a 100644 --- a/backend/src/middlewares/verifytoken.js +++ b/backend/src/middlewares/verifytoken.js @@ -4,7 +4,7 @@ export const verifyToken = (req, res, next) => { const token = req?.headers?.cookie?.split("=")[1]; try { if (!token) { - res.status(401).send({ msg: "No token found" }); + return res.status(401).send({ msg: "No token found" }); } let payload = jwt.verify(token, process.env.SECRET_KEY); if (payload.email) { @@ -15,7 +15,7 @@ export const verifyToken = (req, res, next) => { } else res.status(401).send({ msg: "Invalid Token" }); } catch (error) { - res.status(400).json({ + return res.status(400).json({ msg:"Some Error Occured", error }) diff --git a/backend/src/routes/roomsRouter.js b/backend/src/routes/roomsRouter.js index 4140429..efa3d46 100644 --- a/backend/src/routes/roomsRouter.js +++ b/backend/src/routes/roomsRouter.js @@ -14,7 +14,7 @@ roomsRouter.post('/delete',verifyToken,deleteRoom); roomsRouter.post('/join',verifyToken,addUser) roomsRouter.post('/leave/:roomId',verifyToken,leaveRoom); -roomsRouter.post('/addUserinRoom/:username',verifyToken,sendJoiningRequest) // completing this; +roomsRouter.post('/addUserinRoom/:username',verifyToken,sendJoiningRequest); roomsRouter.post('/acceptJoiningRequest',verifyToken,acceptJoiningRequest); roomsRouter.get('/titleNameIsUnique',verifyToken,filterName) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 4c05695..37135f9 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -74,7 +74,7 @@ function App() { const showSearch = useSelector(state => state.search.value) const showWelcome= useSelector(state=> state.welcome.value) const navigate= useNavigate() - + const myAllRoom = useSelector(state=> state.rooms.rooms); @@ -102,7 +102,7 @@ function App() { dispatch(setNotification(res.data.data)) } catch (error) { console.log(error); - if(error.response.status==401){ + if(error?.response?.status==401){ dispatch(logout()); dispatch(clearUserInfo()); toast.error("Login session expired!"); @@ -206,6 +206,7 @@ function App() { } /> + : }/> : } /> } /> diff --git a/frontend/src/assets/SmoothLoader.jsx b/frontend/src/assets/SmoothLoader.jsx index d19e86f..63150f7 100644 --- a/frontend/src/assets/SmoothLoader.jsx +++ b/frontend/src/assets/SmoothLoader.jsx @@ -2,7 +2,7 @@ const SmoothLoader = (props) => ( { } setIsLoading(false) } - const addUserToRoom = async(title,fromUser)=>{ - // console.clear(); - // console.log(typeof title+""++" "+fromUser); + setBigLoader(true) - const title2 = title.split(":")[1].trim().split(" ")[0].trim() //Here is Some Bug - console.log(title2+" "+fromUser) try { - if(title2 != "Join") - { - - const res = await axios.post(`${baseAddress}rooms//addUserinRoom/${fromUser}`,{ - title: title2 - }) - setBigLoader(false); - toast.success(res?.data.msg); - return; - } const res = await axios.post(`${baseAddress}rooms/acceptJoiningRequest`,{ title, fromUser @@ -90,7 +76,6 @@ const Notification = ({setIsNfnOpen}) => { Navigate(`/post/${item.postId}`); else { - // console.log(item); addUserToRoom(item.body,item.fromUser); } } diff --git a/frontend/src/components/Postdetail.jsx b/frontend/src/components/Postdetail.jsx index a133f0f..6415c6d 100644 --- a/frontend/src/components/Postdetail.jsx +++ b/frontend/src/components/Postdetail.jsx @@ -21,7 +21,7 @@ import baseAddress from '../utils/localhost'; axios.defaults.withCredentials = true -const Postdetail = () => { +const Postdetail = ({ myRooms }) => { const post= useSelector(state=>state.postDetail.post); const userInfo= useSelector(state=>state.user.userInfo); const isLogin= useSelector(state=>state.login.value); @@ -29,8 +29,21 @@ const Postdetail = () => { const dispatch= useDispatch() const location = useLocation(); const {id}= useParams(); + const {roomid} = useParams(); const getApost=async()=>{ + if(myRooms){ + let found = false; + console.log(myRooms); + console.log(roomid); + myRooms.map((room)=>{ + if(room.room.id === roomid)found = true; + }); + if(!found){ + toast.error("Unauthorised"); + return; + } + } try { const res = await axios.get(baseAddress+"posts/getapost", { params:{ diff --git a/frontend/src/components/Posts.jsx b/frontend/src/components/Posts.jsx index dcd1668..46019c0 100644 --- a/frontend/src/components/Posts.jsx +++ b/frontend/src/components/Posts.jsx @@ -48,9 +48,11 @@ const Posts = ({ id, post, title, body, media, countComment, inRoom, room, creat toast.error("First Join The Room"); return; } + } if (!location.pathname.includes('/post/') && id) { - Navigate(`/post/${id}`); + if(inRoom)Navigate(`/post/${room.id}/${id}`); + else Navigate(`/post/${id}`); } }; diff --git a/frontend/src/pages/CreateRoom.jsx b/frontend/src/pages/CreateRoom.jsx index 0058700..77b330d 100644 --- a/frontend/src/pages/CreateRoom.jsx +++ b/frontend/src/pages/CreateRoom.jsx @@ -291,8 +291,8 @@ export default function CreateRoom({showRoom1,setShow,setShow2,heading}) - {Btnloading ? : "Create"} + className="bg-[#656923] hover:bg-[#a9aa88] w-20 text-sm flex justify-center text-black px-4 py-2 font-bold text-justify rounded focus:outline-none"> + {Btnloading ? : "Create"} diff --git a/frontend/src/pages/Room.jsx b/frontend/src/pages/Room.jsx index 2121085..5cec499 100644 --- a/frontend/src/pages/Room.jsx +++ b/frontend/src/pages/Room.jsx @@ -398,7 +398,7 @@ const Room = function () { upvotes={post?.upvotes} inRoom={true} room={data.room} - joined={data.room.joined} + joined={joined} /> ) ) diff --git a/frontend/src/pages/Settings.jsx b/frontend/src/pages/Settings.jsx index 1400628..521bb59 100644 --- a/frontend/src/pages/Settings.jsx +++ b/frontend/src/pages/Settings.jsx @@ -76,7 +76,6 @@ function Settings() { setUsrnmList(res.data.usernames); setUsernameInput(res.data.usernames[0]); - console.log(usernm); } catch (error) { toast.error("Not Able to Generate Username!Try Again Later"); } @@ -135,9 +134,10 @@ function Settings() { let lcdata = await fetch(`https://leetcode-stats-api.herokuapp.com/${lcusername}`); let data = await lcdata.json(); - console.log(data); + // console.log(data); if (data.status == "error") { + setisLoading(false); seterror("Invalid username"); return } @@ -145,7 +145,7 @@ function Settings() { const res = await axios.post(`${baseAddress}u/addLeetCode`, { lcusername: lcusername, }); - console.log(res); + // console.log(res); if (res.status == 200) { dispatch(addLeetCodeID(res.data.leetcode)); setlcdata(data) @@ -169,6 +169,7 @@ function Settings() { console.log("AddCF ",data); if (data.status === "FAILED") { + setisLoading2(false); seterror2("Invalid username"); return; } @@ -176,9 +177,8 @@ function Settings() { const res = await axios.post(`${baseAddress}u/update`, { rank: data.result[0]?.maxRank, }); - console.log("IN ADD CF ",res); - if (res.status == 200) { - dispatch(addCodeforceRank(res.data.codeforces)); + if (res.status == 201) { + dispatch(addCodeforceRank(res.data.user.codeforces)); setupdate2(false) } @@ -191,13 +191,12 @@ function Settings() { const setShowLc = async (value)=>{ setIsDisable(true) - console.log(value); try { const res=await axios.post(`${baseAddress}u/setLcVisibility`, { showLC:value, }) - console.log(res); + // console.log(res); } catch (error) { console.log(error); @@ -208,13 +207,13 @@ function Settings() { const setShowCf = async(value)=>{ setIsDisable2(true) - console.log(value+" "+typeOf(value)); + // console.log(value+" "+typeof (value)); try { const res=await axios.post(`${baseAddress}u/update`, { showCF:value, }) - console.log("setShowCf ",res.data); + // console.log("setShowCf ",res.data); } catch (error) { console.log(error); } @@ -223,14 +222,14 @@ function Settings() { const handleChange2= (e)=>{ setShow2(e.target.checked); - console.log(e.target.checked); + // console.log(e.target.checked); setShowCf(e.target.checked); dispatch(setshowCf(e.target.checked)); } const handleChange= (e)=>{ setShow(e.target.checked); - console.log(e.target.checked); + // console.log(e.target.checked); setShowLc(e.target.checked); dispatch(setShowLC(e.target.checked)) } @@ -262,6 +261,12 @@ function Settings() { setShow(userInfo.showLC) } }, [userInfo?.showLC]) + + useEffect(() => { + if(userInfo){ + setShow2(userInfo.showCf) + } + }, [userInfo?.showCf]) const cancelChanges = ()=>{ setUsernameInput(''); @@ -371,7 +376,7 @@ function Settings() { > : <> - Add Codeforces profile + Add Your Codeforces Rank @@ -409,7 +414,7 @@ function Settings() { - {generateUsername()}} >{generating?: "Generate"} {updating?:'Save'}