Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaloney111 committed Jun 7, 2024
1 parent 670d5a6 commit e1bf060
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 65 deletions.
13 changes: 3 additions & 10 deletions packages/express-backend/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 2 additions & 7 deletions packages/express-backend/services/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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 {
Expand All @@ -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");
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 0 additions & 14 deletions packages/express-backend/web.config

This file was deleted.

2 changes: 0 additions & 2 deletions packages/react-frontend/src/Components/AddOrderTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ function TableBody(props) {
if (props.orderData === null) {
return <caption>Data Unavailable</caption>;
}
//console.log(props.orderData.length);
const rows = props.orderData.map((order, index) => {
//console.log(order);
return (
<tr key={index}>
<td>{order["product"]}</td>
Expand Down
4 changes: 1 addition & 3 deletions packages/react-frontend/src/Components/Logout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
5 changes: 0 additions & 5 deletions packages/react-frontend/src/Components/OrderTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,14 @@ function TableBody(props) {
if (props.orderData === null) {
return <caption>Data Unavailable</caption>;
}
//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 (
Expand Down
1 change: 0 additions & 1 deletion packages/react-frontend/src/Views/EditProfile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
11 changes: 4 additions & 7 deletions packages/react-frontend/src/Views/LoginPage.jsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -18,20 +17,18 @@ 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");
}
return response.text();
})
.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"));
Expand Down
3 changes: 0 additions & 3 deletions packages/react-frontend/src/Views/ManageOrders.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ function ManageOrders() {
} else {
setOrders(null);
}
//console.log(orders);
})
.catch((error) => {
console.log(error);
});
}, []);

function removeOneOrder(order_id) {
//console.log(orders[0]["_id"]);
const updated = orders.filter((order) => {
return order["_id"] !== order_id;
});
Expand Down Expand Up @@ -78,7 +76,6 @@ function ManageOrders() {
} else {
setOrders(null);
}
//console.log(orders);
})
.catch((error) => {
console.log(error);
Expand Down
2 changes: 1 addition & 1 deletion packages/react-frontend/src/Views/ProductPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function ProductPage() {
}

function updateProduct(event) {
event.preventDefault(); // Prevent the default form submission behavior
event.preventDefault();

const updatedProduct = {
product: formValues.product,
Expand Down
3 changes: 1 addition & 2 deletions packages/react-frontend/src/Views/Profile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -78,7 +77,7 @@ function Profile() {
{
Cookies.remove('safeHavenToken');
alert('Profile Deleted');
navigate('/'); //go to homepage
navigate('/');
}
});
}
Expand Down
10 changes: 4 additions & 6 deletions packages/react-frontend/src/Views/SignUpPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Expand Down
4 changes: 0 additions & 4 deletions packages/react-frontend/src/main.jsx
Original file line number Diff line number Diff line change
@@ -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(<MyApp />);

0 comments on commit e1bf060

Please sign in to comment.