Skip to content

Commit

Permalink
Merge branch 'master' into workflows-action
Browse files Browse the repository at this point in the history
HedwigO committed Dec 5, 2023
2 parents 978cef8 + 0a6ce22 commit c670f77
Showing 46 changed files with 1,848 additions and 868 deletions.
31 changes: 31 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# The Group Bill Splitting App

## Description of Project

The Group Bill Splitting App is designed to streamline the process of splitting bills among groups of people. In today's social and financial landscape, individuals often find themselves sharing expenses in various settings, such as dining out, traveling, or living together. This application aims to provide an efficient and user-friendly solution for managing shared expenses, ensuring that everyone pays their fair share effortlessly.

### Product Vision Statement

In a world where coming together and sharing moments are core to our daily lives - whether it's traveling abroad, dining out with friends, going on work trips with colleagues, or handling routine household bills with family - dealing with shared financial responsibilities should be simple and straightforward. Our vision is to introduce a unified platform where handling and dividing shared expenses is as easy as a single click. We aim for an app that makes group financial transactions clear-cut while prioritizing clarity, adaptability, and user comfort. The Group Bill Splitting App is designed to enable users to easily track, manage, and clear their shared expenses, fostering trust and enhancing the pleasure of shared moments without the monetary hassle.

## Core Team Members

- [Allison Ji](https://github.com/Allison67)
- [Joy Chen](https://github.com/joyc7)
- [Cindy Liang](https://github.com/cindyliang01)
- [Laura Zhao](https://github.com/HedwigO)
- [Elaine Zhang](https://github.com/elaineZhang67)

## Contribution

Please refer to [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to this project.

## Instructions for Building and Testing

To be updated

## Additional Links

- [User Experience Design](UX-DESIGN.md)

## Notes
2 changes: 0 additions & 2 deletions .github/readme.txt

This file was deleted.

4 changes: 4 additions & 0 deletions back-end/app.js
Original file line number Diff line number Diff line change
@@ -22,6 +22,8 @@ const logoutRoute = require("./routes/logoutRoute");
const searchFriendRoute = require("./routes/searchFriendRoute");
const expenseRoute = require("./routes/expenseRoute");
const settlementRoute = require("./routes/settlementRoute");
const expenseStatusRoute = require("./routes/expenseStatusRoute");
const searchUserInfoRoute = require("./routes/searchUserInfoRoute");

// connect to the database
// console.log(`Conneting to MongoDB at ${process.env.MONGODB_URI}`)
@@ -62,6 +64,8 @@ app.use("/logout", logoutRoute);
app.use("/searchFriend", searchFriendRoute);
app.use("/expense", expenseRoute);
app.use("/settlement", settlementRoute);
app.use("/search-user-info", searchUserInfoRoute);
app.use("/expenseStatus", expenseStatusRoute);

// export the express app we created to make it available to other modules
module.exports = app;
1 change: 1 addition & 0 deletions back-end/models/Settlement.js
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ const settlementSchema = new Schema({
settleTo: { type: mongoose.Schema.Types.ObjectId, ref: "User" },
settleFrom: { type: mongoose.Schema.Types.ObjectId, ref: "User" },
event: { type: mongoose.Schema.Types.ObjectId, ref: "Event" },
expense: { type: mongoose.Schema.Types.ObjectId, ref: "Expense" },
});

// create mongoose Model
2 changes: 1 addition & 1 deletion back-end/package.json
Original file line number Diff line number Diff line change
@@ -27,6 +27,6 @@
"chai": "^4.3.10",
"chai-http": "^4.4.0",
"mocha": "^10.2.0",
"nodemon": "^3.0.1"
"nodemon": "^3.0.2"
}
}
16 changes: 9 additions & 7 deletions back-end/routes/addExpensePayerRoute.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
const express = require("express");
const router = express.Router();
const {User} = require("../models/User.js")
const { User } = require("../models/User.js");
const Event = require("../models/Event.js");

router.get('/EventMember/:eventId', async (req, res) => {
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');
console.log("eventId:", eventId);
const eventMember = await Event.findById(eventId).populate("participants");
if (!eventMember) {
return res.status(404).json({ message: "Event not found or you don't have access to it" });
return res
.status(404)
.json({ message: "Event not found or you don't have access to it" });
}
res.json(eventMember.participants);
}catch (error) {
} catch (error) {
console.error("Error fetching event members:", error);
res.status(500).json({ message: "Server error", error});
res.status(500).json({ message: "Server error", error });
}
});

55 changes: 26 additions & 29 deletions back-end/routes/addExpenseRoute.js
Original file line number Diff line number Diff line change
@@ -25,63 +25,60 @@ router.post(
console.log("validation passed");

try {

let splitDetailsWithSettlements = [];
// Create Settlement objects
for (const split of req.body.peopleSplit) {
if (split.user !== req.body.paidBy) {
let newSettlement = new Settlement({
status: false,
amount: split.amount,
settleTo: req.body.paidBy,
settleFrom: split.user,
event: req.body.event,
});
console.log(newSettlement);
await newSettlement.save();
splitDetailsWithSettlements.push({ user: split.user, settlement: newSettlement._id });
}
}

// Create a new Expense object
const newExpense = new Expense({
name: req.body.name,
description: req.body.description,
totalAmount: req.body.totalAmount,
date: new Date(req.body.date),
paidBy: req.body.paidBy,
splitDetails: splitDetailsWithSettlements,
event: req.body.event,
});

console.log(newExpense);
const savedExpense = await newExpense.save();

let splitDetailsWithSettlements = [];
for (const split of req.body.peopleSplit) {
const settleTo = req.body.paidBy;
const settleFrom = split.user;
let newSettlement = new Settlement({
status: settleTo.toString() === settleFrom._id.toString(),
amount: split.amount,
settleTo: settleTo,
settleFrom: settleFrom,
event: req.body.event,
expense: savedExpense._id,
});

await newSettlement.save();
splitDetailsWithSettlements.push({
user: split.user,
settlement: newSettlement._id,
});
}

savedExpense.splitDetails = splitDetailsWithSettlements;
await savedExpense.save();

// Save the Expense object to the database
const event = await Event.findById(req.body.event);
if (!event) {
return res
.status(404)
.json({ status: "Error", message: "Event not found" });
}

// Add the expense ID to the event's expenses list
// ? no "savedExpense" defined, maybe "newExpense"?
const savedExpense = await newExpense.save();
event.expenses.push(savedExpense._id);
await event.save();

// Send a success response
res.status(201).json({
status: "Success",
message: "Expense added successfully",
data: newExpense,
data: savedExpense,
});
} catch (error) {
// Handle any errors that occur during saving to database
console.log(error);
res.status(500).json({ status: "Error", message: error.message });
}
}
);

module.exports = router;
module.exports = router;
53 changes: 26 additions & 27 deletions back-end/routes/addFriendRoute.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
const express = require('express');
const express = require("express");
const router = express.Router();
const { User } = require("../models/User.js");

router.post('/', async (req, res) => {
const { currentUserId, friendUserId } = req.body;
router.post("/", async (req, res) => {
const { currentUserId, friendUserId } = req.body;

try {
const currentUser = await User.findById(currentUserId);
const friendUser = await User.findById(friendUserId);
try {
const currentUser = await User.findById(currentUserId);
const friendUser = await User.findById(friendUserId);

if (!currentUser || !friendUser) {
return res.status(404).send("One or both users not found");
}

if (!currentUser.friends.includes(friendUserId)) {
currentUser.friends.push(friendUserId);
await currentUser.save();
console.log(`Added ${friendUserId} to ${currentUser.id}'s friends list.`);
} else {
return res.status(200).send("Already friends");
}
if (!currentUser || !friendUser) {
return res.status(404).send("One or both users not found");
}

if (!friendUser.friends.includes(currentUserId)) {
friendUser.friends.push(currentUserId);
await friendUser.save();
}
if (!currentUser.friends.includes(friendUserId)) {
currentUser.friends.push(friendUserId);
await currentUser.save();
console.log(`Added ${friendUserId} to ${currentUser.id}'s friends list.`);
} else {
return res.status(200).send("Already friends");
}

res.status(200).send("Friends added successfully");

} catch (error) {
console.error("Error in addFriend route:", error);
res.status(500).send("Error adding friend");
if (!friendUser.friends.includes(currentUserId)) {
friendUser.friends.push(currentUserId);
await friendUser.save();
}

res.status(200).send("Friends added successfully");
} catch (error) {
console.error("Error in addFriend route:", error);
res.status(500).send("Error adding friend");
}
});

module.exports = router;
module.exports = router;
8 changes: 6 additions & 2 deletions back-end/routes/eventRoute.js
Original file line number Diff line number Diff line change
@@ -7,9 +7,13 @@ router.get("/:eventId", async (req, res) => {
const eventId = req.params.eventId;
const event = await Event.findById(eventId).populate({
path: "expenses",
model: "Expense"
model: "Expense",
populate: {
path: "splitDetails.settlement",
model: "Settlement",
},
});

if (!event) {
return res.status(404).json({ message: "Event not found" });
}
11 changes: 10 additions & 1 deletion back-end/routes/eventsRoute.js
Original file line number Diff line number Diff line change
@@ -92,9 +92,18 @@ router.get("/for/:userId", async (req, res) => {
const userId = req.params.userId;

// Fetch the user and populate the events
const userWithEvents = await User.findById(userId).populate({
const userWithEvents = await User.findById(userId)
.populate({
path: "events",
model: "Event",
populate:{
path: "expenses",
model: "Expense",
populate: {
path: "splitDetails.settlement",
model: "Settlement",
}
}
});

if (!userWithEvents) {
64 changes: 32 additions & 32 deletions back-end/routes/expenseRoute.js
Original file line number Diff line number Diff line change
@@ -3,37 +3,37 @@ const router = express.Router();
const { Expense } = require("../models/Expense.js");

router.get("/ExpenseDetail/:expenseId", async (req, res) => {
try {
const expenseId = req.params.expenseId;

const expenseSplit = await Expense.findById(expenseId)
.populate('event')
.populate({
path: 'splitDetails',
populate: {
path: 'settlement',
model: 'Settlement'
}
})
.populate({
path: 'splitDetails',
populate: {
path: 'user',
model: 'User'
}
})

if (!expenseSplit) {
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);
res.status(500).json({ message: "Server error" , error});
}
});
try {
const expenseId = req.params.expenseId;

const expenseSplit = await Expense.findById(expenseId)
.populate("event")
.populate('paidBy', 'username')
.populate({
path: "splitDetails",
populate: {
path: "settlement",
model: "Settlement",
},
})
.populate({
path: "splitDetails",
populate: {
path: "user",
model: "User",
},
});

if (!expenseSplit) {
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);
res.status(500).json({ message: "Server error", error });
}
});

module.exports = router;
module.exports = router;
Loading

0 comments on commit c670f77

Please sign in to comment.