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) => (
@@ -409,7 +414,7 @@ function Settings() {
- {generateUsername()}} >{generating?: "Generate"} {updating?:'Save'}