From e1bf060f567d483bb7adb27503ec1c1bad049406 Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 7 Jun 2024 05:46:52 -0700 Subject: [PATCH] fix comments --- packages/express-backend/backend.js | 13 +++---------- packages/express-backend/services/user-service.js | 9 ++------- packages/express-backend/web.config | 14 -------------- .../src/Components/AddOrderTable.jsx | 2 -- packages/react-frontend/src/Components/Logout.jsx | 4 +--- .../react-frontend/src/Components/OrderTable.jsx | 5 ----- packages/react-frontend/src/Views/EditProfile.jsx | 1 - packages/react-frontend/src/Views/LoginPage.jsx | 11 ++++------- packages/react-frontend/src/Views/ManageOrders.jsx | 3 --- packages/react-frontend/src/Views/ProductPage.jsx | 2 +- packages/react-frontend/src/Views/Profile.jsx | 3 +-- packages/react-frontend/src/Views/SignUpPage.jsx | 10 ++++------ packages/react-frontend/src/main.jsx | 4 ---- 13 files changed, 16 insertions(+), 65 deletions(-) delete mode 100644 packages/express-backend/web.config diff --git a/packages/express-backend/backend.js b/packages/express-backend/backend.js index eb2aea3..e592971 100644 --- a/packages/express-backend/backend.js +++ b/packages/express-backend/backend.js @@ -12,7 +12,7 @@ const port = 8000; app.use(cors()); app.use(express.json()); -// Routes + const upload = multer({ dest: "uploads/" }); app.use("/uploads", express.static("uploads")); @@ -87,7 +87,7 @@ app.post("/users", (req, res) => { }); app.post("/users/profile", userService.authenticateUser, (req, res) => { - const { bio, skills } = req.body; // from form + const { bio, skills } = req.body; const id = req.userID; userService.editProfile(id, bio, skills) .then((result) => { @@ -226,8 +226,6 @@ app.patch("/products/:id", userService.authenticateUser, (req, res) => { }); app.get("/products", userService.authenticateUser, async (req, res) => { - // const product = req.query.product; - // const quantity = req.query.quantity; const UserID = req.userID; try { const user = await userService.findUserById(UserID); @@ -247,11 +245,8 @@ app.get("/", (req, res) => { res.send("Hello World!"); }); -//add_orders routes + app.get("/orders", userService.authenticateUser, async (req, res) => { - //const id = req.query.id; - //const product = req.query.product; - //const quantity = req.query.quantity; const search = req.query.search; const UserID = req.userID; const user = await userService.findUserById(UserID); @@ -332,8 +327,6 @@ app.delete("/orders/:id", userService.authenticateUser, (req, res) => { }); }); - -//order-units routes app.get("/order-units", userService.authenticateUser, (req, res) => { const id = req.query.id; const product = req.query.product; diff --git a/packages/express-backend/services/user-service.js b/packages/express-backend/services/user-service.js index ddda3cf..44d96e6 100644 --- a/packages/express-backend/services/user-service.js +++ b/packages/express-backend/services/user-service.js @@ -46,14 +46,12 @@ function getUsers(username, name, profilePicture) { } function getPassword(username) { - //same as get Users but uses findOne let query = {}; query.username = username; return UserModel.findOne(query, { _id: 1, password: 1 }); } function getUsername(username) { - //same as get Users but uses findOne let query = {}; query.username = username; return UserModel.findOne(query, { _id: 1, username: 1 }); @@ -93,8 +91,8 @@ function loginUser(req, res) { }); } function signupUser(req, res) { - const salt = "$2b$10$5u3nVKlTV5RPpREyblmGqe"; //pregenerated salt - const { username, password } = req.body; // from form + const salt = "$2b$10$5u3nVKlTV5RPpREyblmGqe"; + const { username, password } = req.body; if (!username || !password) { res.status(400).send("Bad request: Invalid input data."); } else { @@ -121,7 +119,6 @@ function signupUser(req, res) { function authenticateUser(req, res, next) { const authHeader = req.headers["authorization"]; - //Getting the 2nd part of the auth header (the token) const token = authHeader && authHeader.split(" ")[1]; if (!token) { console.log("No token received"); @@ -130,7 +127,6 @@ function authenticateUser(req, res, next) { jwt.verify(token, process.env.TOKEN_SECRET, (error, decoded) => { if (decoded) { req.userID = decoded._id; - //console.log(req.userID); next(); } else { console.log("JWT error:", error); @@ -179,7 +175,6 @@ function addUser(user) { async function addProductToUser(id, productId) { try { - // Find the user and add the product to their list console.log(id); const user = await UserModel.findById(id); if (!user) { diff --git a/packages/express-backend/web.config b/packages/express-backend/web.config deleted file mode 100644 index be65299..0000000 --- a/packages/express-backend/web.config +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/packages/react-frontend/src/Components/AddOrderTable.jsx b/packages/react-frontend/src/Components/AddOrderTable.jsx index c6bedf7..8e9806f 100644 --- a/packages/react-frontend/src/Components/AddOrderTable.jsx +++ b/packages/react-frontend/src/Components/AddOrderTable.jsx @@ -16,9 +16,7 @@ function TableBody(props) { if (props.orderData === null) { return Data Unavailable; } - //console.log(props.orderData.length); const rows = props.orderData.map((order, index) => { - //console.log(order); return ( {order["product"]} diff --git a/packages/react-frontend/src/Components/Logout.jsx b/packages/react-frontend/src/Components/Logout.jsx index 9c5657f..2da9ca9 100644 --- a/packages/react-frontend/src/Components/Logout.jsx +++ b/packages/react-frontend/src/Components/Logout.jsx @@ -6,14 +6,12 @@ const Logout = () => { const navigate = useNavigate(); useEffect(() => { - // Remove the cookie Cookies.remove('safeHavenToken'); - // Redirect to the homepage navigate("/"); }, [navigate]); - return null; // This component does not need to render anything + return null; }; export default Logout; \ No newline at end of file diff --git a/packages/react-frontend/src/Components/OrderTable.jsx b/packages/react-frontend/src/Components/OrderTable.jsx index 8ef9437..ea22e08 100644 --- a/packages/react-frontend/src/Components/OrderTable.jsx +++ b/packages/react-frontend/src/Components/OrderTable.jsx @@ -47,19 +47,14 @@ function TableBody(props) { if (props.orderData === null) { return Data Unavailable; } - //console.log(props.orderData); const rows = props.orderData.map((order, index) => { let arr_order = Array(order["items"]); - //console.log(order["_id"]) console.log(order) if (order != undefined) { let each_item = arr_order.map((item) => { console.log(item); let item_arr = JSON.stringify(item).split(","); let item_id = item_arr[0].slice(item_arr[0].indexOf('"_id":') + 7, item_arr[0].length - 1); - //console.log(item_id); - //item = convertToDict(JSON.stringify(item)); - //const item_count = item[0]["item_count"]; let each_product = item.map((product, index) => { console.log(product); return ( diff --git a/packages/react-frontend/src/Views/EditProfile.jsx b/packages/react-frontend/src/Views/EditProfile.jsx index 5d23192..2327845 100644 --- a/packages/react-frontend/src/Views/EditProfile.jsx +++ b/packages/react-frontend/src/Views/EditProfile.jsx @@ -17,7 +17,6 @@ function EditProfile() { }) .then((response) => { if (!response.ok) { - // Handle the case where the server returns an error throw new Error("User Not Found (Invalid Token)"); } navigate("/profile"); diff --git a/packages/react-frontend/src/Views/LoginPage.jsx b/packages/react-frontend/src/Views/LoginPage.jsx index f994e98..5577bff 100644 --- a/packages/react-frontend/src/Views/LoginPage.jsx +++ b/packages/react-frontend/src/Views/LoginPage.jsx @@ -1,5 +1,4 @@ import React, { useState, useEffect } from "react"; -//import Table from "../Components/Table"; import Auth from "../Components/Auth"; import "../Styles/Navbar.css"; import Cookies from "js-cookie"; @@ -18,7 +17,6 @@ function Login() { }) .then((response) => { if (!response.ok) { - // Handle the case where the server returns an error alert("Invalid username/password"); throw new Error("Invalid username/password"); } @@ -26,12 +24,11 @@ function Login() { }) .then((token) => { Cookies.remove("safeHavenToken"); - // Here, 'token' contains the JWT token sent from the server Cookies.set("safeHavenToken", token, { - expires: 24 / 24, // 1 hour in days - path: "/", // cookie path - secure: false, // set to true if using HTTPS - sameSite: "strict" // or 'lax' depending on your requirements + expires: 24 / 24, + path: "/", + secure: false, + sameSite: "strict" }); console.log(token); console.log(Cookies.get("safeHavenToken")); diff --git a/packages/react-frontend/src/Views/ManageOrders.jsx b/packages/react-frontend/src/Views/ManageOrders.jsx index 6f15659..9fc4b91 100644 --- a/packages/react-frontend/src/Views/ManageOrders.jsx +++ b/packages/react-frontend/src/Views/ManageOrders.jsx @@ -17,7 +17,6 @@ function ManageOrders() { } else { setOrders(null); } - //console.log(orders); }) .catch((error) => { console.log(error); @@ -25,7 +24,6 @@ function ManageOrders() { }, []); function removeOneOrder(order_id) { - //console.log(orders[0]["_id"]); const updated = orders.filter((order) => { return order["_id"] !== order_id; }); @@ -78,7 +76,6 @@ function ManageOrders() { } else { setOrders(null); } - //console.log(orders); }) .catch((error) => { console.log(error); diff --git a/packages/react-frontend/src/Views/ProductPage.jsx b/packages/react-frontend/src/Views/ProductPage.jsx index 5e7b828..3f4bb2e 100644 --- a/packages/react-frontend/src/Views/ProductPage.jsx +++ b/packages/react-frontend/src/Views/ProductPage.jsx @@ -50,7 +50,7 @@ function ProductPage() { } function updateProduct(event) { - event.preventDefault(); // Prevent the default form submission behavior + event.preventDefault(); const updatedProduct = { product: formValues.product, diff --git a/packages/react-frontend/src/Views/Profile.jsx b/packages/react-frontend/src/Views/Profile.jsx index b6953b4..f98b96e 100644 --- a/packages/react-frontend/src/Views/Profile.jsx +++ b/packages/react-frontend/src/Views/Profile.jsx @@ -48,7 +48,6 @@ function Profile() { formData.append("profilePicture", file); try { - // Send the file to the server for processing and storage in MongoDB const response = await axios.post("https://safehavenapp.azurewebsites.net//profile-picture", formData, { headers: addAuthHeader({ "Content-Type": "multipart/form-data" @@ -78,7 +77,7 @@ function Profile() { { Cookies.remove('safeHavenToken'); alert('Profile Deleted'); - navigate('/'); //go to homepage + navigate('/'); } }); } diff --git a/packages/react-frontend/src/Views/SignUpPage.jsx b/packages/react-frontend/src/Views/SignUpPage.jsx index 4301548..40b7b0c 100644 --- a/packages/react-frontend/src/Views/SignUpPage.jsx +++ b/packages/react-frontend/src/Views/SignUpPage.jsx @@ -17,21 +17,19 @@ function Signup() { }) .then((response) => { if (!response.ok) { - // Handle the case where the server returns an error alert("Username already taken"); throw new Error("Username already taken"); } return response.text(); }) .then((token) => { - // Here, 'token' contains the JWT token sent from the server console.log(token); Cookies.remove("safeHavenToken"); Cookies.set("safeHavenToken", token, { - expires: 24 / 24, // 1 hour in days - path: "/", // cookie path - secure: false, // set to true if using HTTPS - sameSite: "strict" // or 'lax' depending on your requirements + expires: 24 / 24, + path: "/", + secure: false, + sameSite: "strict" }); navigate("/inventory"); }); diff --git a/packages/react-frontend/src/main.jsx b/packages/react-frontend/src/main.jsx index f32fc32..8b8d703 100644 --- a/packages/react-frontend/src/main.jsx +++ b/packages/react-frontend/src/main.jsx @@ -1,14 +1,10 @@ -// src/main.jsx import React from "react"; import ReactDOMClient from "react-dom/client"; import MyApp from "./MyApp"; import "./Styles/main.css"; -// Create the container const container = document.getElementById("root"); -// Create a root const root = ReactDOMClient.createRoot(container); -// Initial render: Render an element to the Root root.render();