Skip to content

Commit

Permalink
added user and expense model
Browse files Browse the repository at this point in the history
  • Loading branch information
shobhit10058 committed Dec 12, 2022
1 parent f21aed6 commit d5cfad4
Show file tree
Hide file tree
Showing 4 changed files with 250 additions and 7 deletions.
24 changes: 24 additions & 0 deletions backend/models/expense.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const mongoose = require('mongoose')
const Schema = mongoose.Schema

let expenseSchema = new Schema({
userID: {
type: Schema.Types.ObjectId,
ref: "User"
},
amount: {
type: [
{
category: String,
value: Number
}
],
default: []
},
date: {
type: Date,
default: Date.now
}
});

module.exports = mongoose.model('Expense', expenseSchema);
31 changes: 27 additions & 4 deletions backend/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,30 @@ const mongoose = require('mongoose')
const Schema = mongoose.Schema

let userSchema = new Schema({
username: String,
password: String,

})
username: {
type: String,
required: true,
unique: true
},
password: {
type: String,
required: true
},
budget: {
type: Number,
default: 0
},
categories: {
type: [String],
default: []
},
todaysExpenseID: {
type: Schema.Types.ObjectId,
ref: "Expense"
}
})

const userModel = mongoose.model('User', userSchema);
userModel.createIndexes();

module.exports = userModel;
200 changes: 197 additions & 3 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.8.0"
},
"devDependencies": {
Expand Down

0 comments on commit d5cfad4

Please sign in to comment.