Skip to content

Commit

Permalink
bugfixing
Browse files Browse the repository at this point in the history
  • Loading branch information
imdeveshshukla committed Aug 22, 2024
1 parent d01220c commit 1cf0b3c
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 60 deletions.
1 change: 0 additions & 1 deletion backend/src/controller/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 12 additions & 10 deletions backend/src/controller/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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({
Expand All @@ -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,
Expand All @@ -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"
Expand Down
8 changes: 3 additions & 5 deletions backend/src/controller/upvotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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,
});
Expand All @@ -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,
});
Expand Down
5 changes: 3 additions & 2 deletions backend/src/controller/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:{
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions backend/src/middlewares/verifytoken.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
})
Expand Down
2 changes: 1 addition & 1 deletion backend/src/routes/roomsRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);



Expand Down Expand Up @@ -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!");
Expand Down Expand Up @@ -206,6 +206,7 @@ function App() {
<Route path='commented' element={<ProfileComments />} />
</Route>

<Route path='/post/:roomid/:id' element={isSkelton ? <Postskelton /> : <Postdetail myRooms={myAllRoom}/>}/>

<Route path='/post/:id' element={isSkelton ? <Postskelton /> : <Postdetail />} />
<Route path='/q/sports' element={<HotTopicPosts topic={"sports"} title={"Sports"} dp={sportsdp} bg={sportsbg} />} />
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/assets/SmoothLoader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const SmoothLoader = (props) => (
<svg
aria-hidden="true"
role="status"
className="inline w-4 h-4 me-3 text-gray-200 animate-spin text-gray-600"
className="inline w-4 h-4 me-3 animate-spin text-gray-600"
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg"
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/AddMemBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default function AddMemBox({ setShow, id }) {
console.log(canSend);

if(!canSend) return;
console.log(id+" "+title);
setLoading(true);
try {
const res = await axios.post(`${baseAddress}rooms/addUserinRoom/${title}`, {
Expand Down
17 changes: 1 addition & 16 deletions frontend/src/components/Notification.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,10 @@ const Notification = ({setIsNfnOpen}) => {
}
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
Expand Down Expand Up @@ -90,7 +76,6 @@ const Notification = ({setIsNfnOpen}) => {
Navigate(`/post/${item.postId}`);
else
{
// console.log(item);
addUserToRoom(item.body,item.fromUser);
}
}
Expand Down
15 changes: 14 additions & 1 deletion frontend/src/components/Postdetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,29 @@ 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);
const Navigate= useNavigate()
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:{
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/Posts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
};

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/CreateRoom.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ export default function CreateRoom({showRoom1,setShow,setShow2,heading})
</button>
<button
onClick={handleSubmit}
className="bg-[#656923] hover:bg-[#a9aa88] w-20 text-sm text-black px-4 py-2 font-bold text-justify rounded focus:outline-none">
{Btnloading ? <SmallLoader /> : "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 ? <SmoothLoader /> : "Create"}
</button>

</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Room.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ const Room = function () {
upvotes={post?.upvotes}
inRoom={true}
room={data.room}
joined={data.room.joined}
joined={joined}
/>
)
)
Expand Down
Loading

0 comments on commit 1cf0b3c

Please sign in to comment.