Skip to content

Commit

Permalink
Sync product and order names
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaloney111 committed Jun 7, 2024
1 parent 6f945d0 commit 00c7e4a
Show file tree
Hide file tree
Showing 14 changed files with 966 additions and 946 deletions.
29 changes: 18 additions & 11 deletions packages/express-backend/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ app.post(

const pfp = { profilePicture: result._id };

fetch(`https://safehaven2.azurewebsites.net/users/${user._id}`, {
fetch(`safehaven307.azurewebsites.net/users/${user._id}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json"
Expand Down Expand Up @@ -355,15 +355,22 @@ app.get("/order-units/:id", userService.authenticateUser, (req, res) => {

app.post("/order-units", userService.authenticateUser, (req, res) => {
const orderToAdd = req.body;
//console.log("POST: ", req.body);
orderUnitService
.addOrder(orderToAdd)
.then((result) => {
res.status(201).send(result);
})
.catch((error) => {
res.status(500).send(error.name);
});
const UserID = req.userID;
console.log(orderToAdd);
userService.hasProduct(UserID, orderToAdd.product).then(has => {
if (has) {
orderUnitService
.addOrder(orderToAdd)
.then((result) => {
res.status(201).send(result);
})
} else {
res.status(204).send(orderToAdd.product);
}
})
.catch(error => {
res.status(500).json({ error: error.name });
});
});

app.delete("/order-units/:id", userService.authenticateUser, (req, res) => {
Expand All @@ -378,6 +385,6 @@ app.delete("/order-units/:id", userService.authenticateUser, (req, res) => {
});
});

app.listen(port, () => {
app.listen(process.env.PORT || port, () => {
console.log(`Example app listening at safehaven307.azurewebsites.net:${port}`);
});
21 changes: 15 additions & 6 deletions packages/express-backend/services/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,11 @@ async function addProductToUser(id, productId) {
}

function removeProductFromUserID(userID, productIDToRemove) {
console.log("HELLO");
return UserModel.updateOne({ _id: userID }, { $pull: { products: productIDToRemove } });
}

async function addOrderToUser(id, orderId) {
try {
// Find the user and add the product to their list
console.log(id);
const user = await UserModel.findById(id);
if (!user) {
throw new Error("User not found");
Expand All @@ -219,9 +216,20 @@ async function addOrderToUser(id, orderId) {
}

function removeOrderFromUserID(userID, orderIDToRemove) {
console.log("HELLO");
return UserModel.updateOne({ _id: userID }, { $pull: { orders: orderIDToRemove } });
}

async function hasProduct(userID, productName) {
const user = await findUserById(userID).populate("products");
if (!user || !user.products) {
return false;
}
console.log("delapaz")
console.log(user.products)
console.log(productName)
return user.products.some(product => product.product === productName);
}

export default {
addUser,
removeUser,
Expand All @@ -237,5 +245,6 @@ export default {
addProductToUser,
removeProductFromUserID,
addOrderToUser,
removeOrderFromUserID
};
removeOrderFromUserID,
hasProduct
};
2 changes: 1 addition & 1 deletion packages/react-frontend/src/Components/OrderForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function OrderForm(props) {

const addToList = () => {
props.handleSubmit(order);
setOrder({ product: "", quantity: "" }); // Reset form state
setOrder({ product: "", quantity: "" });
};

return (
Expand Down
56 changes: 28 additions & 28 deletions packages/react-frontend/src/Views/AboutUs.jsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import React from "react";
import "../Styles/Profile.css";
import "../Styles/Navbar.css";

function AboutUs() {

return (
<div>
<div className="about-us-container">
<div className="profile-bio">
<h3>About Us</h3>
<div>
<text>
SafeHaven is a company dedicated to optimizing storage management solutions for businesses.
Our product scales easily, displays critical order insights, and is affordably priced.
</text>
</div>
<div>
<text>Choose SafeHaven!</text>
</div>
</div>
</div>
<div className="bottom-margin"></div>
</div>
);
}

export default AboutUs;
import React from "react";
import "../Styles/Profile.css";
import "../Styles/Navbar.css";

function AboutUs() {

return (
<div>
<div className="about-us-container">
<div className="profile-bio">
<h3>About Us</h3>
<div>
<text>
SafeHaven is a company dedicated to optimizing storage management solutions for businesses.
Our product scales easily, displays critical order insights, and is affordably priced.
</text>
</div>
<div>
<text>Choose SafeHaven!</text>
</div>
</div>
</div>
<div className="bottom-margin"></div>
</div>
);
}

export default AboutUs;
Loading

0 comments on commit 00c7e4a

Please sign in to comment.