Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up backend code #231

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions back-end/routes/addEventRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ router.post(
expenses: [], // initialize this as empty
});

console.log(newEvent);

const savedEvent = await newEvent.save();

console.log("Event created:", savedEvent);

// Fetch and update each participant
for (const userId of req.body.Members) {
let user = await User.findById(userId);
Expand All @@ -52,7 +48,6 @@ router.post(
}

await user.save();
console.log(`Event added to user ${userId}`);
}

res.status(201).json({
Expand Down
1 change: 0 additions & 1 deletion back-end/routes/addExpensePayerRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ router.get("/EventMember/:eventId", async (req, res) => {
try {
//fetch all data
const eventId = req.params.eventId;
console.log("eventId:", eventId);
const eventMember = await Event.findById(eventId).populate("participants");
if (!eventMember) {
return res
Expand Down
1 change: 0 additions & 1 deletion back-end/routes/addExpenseRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ router.post(
data: savedExpense,
});
} catch (error) {
console.log(error);
res.status(500).json({ status: "Error", message: error.message });
}
}
Expand Down
3 changes: 1 addition & 2 deletions back-end/routes/expenseRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ router.get("/ExpenseDetail/:expenseId", async (req, res) => {

const expenseSplit = await Expense.findById(expenseId)
.populate("event")
.populate('paidBy', 'username')
.populate("paidBy", "username")
.populate({
path: "splitDetails",
populate: {
Expand All @@ -28,7 +28,6 @@ router.get("/ExpenseDetail/:expenseId", async (req, res) => {
return res.status(404).json({ message: "Expense not found" });
}
// Return the user's events
console.log(expenseSplit);
res.json(expenseSplit);
} catch (error) {
console.error("Error fetching expense details:", error);
Expand Down
7 changes: 0 additions & 7 deletions back-end/routes/loginRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ router.post("/", async function (req, res, next) {
const username = req.body.username;
const password = req.body.password;

// if (!username || !password) {
// res
// .status(401)
// .json({ success: false, message: `No username or password supplied.` });
// next();
// }

if (!username || !password) {
return res
.status(401)
Expand Down
4 changes: 0 additions & 4 deletions back-end/routes/sendMessageRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ router.post("/", async (req, res) => {
user: req.body.user,
});

console.log(newMessage);

const savedMessage = await newMessage.save();

console.log("Event created:", savedMessage);

res.status(201).json({
status: "Success",
message: "Message sent successfully!",
Expand Down
9 changes: 4 additions & 5 deletions back-end/routes/settlementRoute.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const express = require("express");
const router = express.Router();
const { Settlement } = require("../models/Settlement.js");
const { Expense } = require("../models/Expense.js")
const { Expense } = require("../models/Expense.js");

// Route to get settlements for a specific user as 'settleFrom'
router.get("/from/:userId", async (req, res) => {
try {
const userId = req.params.userId;

const settlements = await Settlement.find({
$or: [{ settleFrom: userId }, { settleTo: userId }]
$or: [{ settleFrom: userId }, { settleTo: userId }],
})
.populate("settleTo")
.populate("settleFrom")
Expand All @@ -18,13 +18,12 @@ router.get("/from/:userId", async (req, res) => {
model: "Expense",
populate: {
path: "paidBy",
model: "User"
}
model: "User",
},
})
.populate("event");

res.status(200).json(settlements);
console.log(settlements)
} catch (error) {
res
.status(500)
Expand Down
26 changes: 13 additions & 13 deletions back-end/routes/userInfoPageRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ const router = express.Router();
const { User } = require("../models/User.js");

router.get("/:userId", async (req, res) => {
try {
const userId = req.params.userId;
const user = await User.findById(userId);

if (!user) {
return res.status(404).json({ message: "User not found" });
}

res.json(user);
} catch (error) {
console.error("Error fetching user:", error);
res.status(500).json({ message: "Error fetching user data" });
try {
const userId = req.params.userId;
const user = await User.findById(userId);

if (!user) {
return res.status(404).json({ message: "User not found" });
}
});

res.json(user);
} catch (error) {
console.error("Error fetching user:", error);
res.status(500).json({ message: "Error fetching user data" });
}
});

module.exports = router;
Loading