Skip to content

Commit

Permalink
Merge pull request #11 from BUMETCS673/hw97_update_db_ids_numeric
Browse files Browse the repository at this point in the history
Change ID schemas to be numeric instead of string
  • Loading branch information
amanda-yee authored Sep 22, 2024
2 parents bd55835 + e654476 commit 8f6c7c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
8 changes: 4 additions & 4 deletions code/server/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ let progressSchema = new Schema({
});

let goalSchema = new Schema({
goalId: { type: String, required: true },
goalId: { type: Number, required: true },
type: { type: String, required: true },
targetValue: { type: String, required: true },
unit: { type: String, required: true },
createdAt: { type: Date, default: Date.now },
progress: {type: [progressSchema], required: false } //type: [goalSchema] once that is created
progress: {type: [progressSchema], default: [] }
}, {
collection: 'goals'
})

let userSchema = new Schema({
userId: { type: String, required: true },
userId: { type: Number, required: true },
email: { type: String, required: true },
passwordHashed: { type: String, required: true },
name: { type: String, required: true },
createdAt: { type: Date, default: Date.now },
goals: {type: [goalSchema], required: false } //type: [goalSchema] once that is created
goals: {type: [goalSchema], default: [] }
}, {
collection: 'users'
})
Expand Down
17 changes: 13 additions & 4 deletions code/server/initdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@ async function init() {
// await Goal.deleteMany({})

let goal1 = new Goal({
goalId: "G10001",
goalId: 50001,
type: "sleep",
targetValue: 8,
unit: "hours",
createdAt: "2024-09-10",
progress: [{date: new Date("2024-09-11"), value: 7.5},
{date: new Date("2024-09-12"), value: 8}]
})

let goal2 = new Goal({
goalId: 50002,
type: "steps",
targetValue: 9000,
unit: "steps",
// will use defaults for createdAt and progress
})

let user1 = new User({
userId: "U10001",
userId: 10001,
email: "[email protected]",
passwordHashed: "pa55w0rd",
name: "John Smith",
Expand All @@ -31,7 +39,7 @@ async function init() {
})

let user2 = new User({
userId: "U10002",
userId: 10002,
email: "[email protected]",
passwordHashed: "b0st0nuniversity",
name: "Jane Doe",
Expand All @@ -42,7 +50,8 @@ async function init() {
await Promise.all([
user1.save(),
user2.save(),
goal1.save()
goal1.save(),
goal2.save()
])

let users = await User.find({})
Expand Down

0 comments on commit 8f6c7c2

Please sign in to comment.