-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from BUMETCS673/hw97_create_dummy_user_data
HW97 Create user and goal data based on UML
- Loading branch information
Showing
2 changed files
with
59 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,40 +3,58 @@ | |
const db = require("./db.js") | ||
|
||
const User = db.getModel().userModel | ||
const Goal = db.getModel().goalModel | ||
|
||
async function init() { | ||
|
||
try { | ||
|
||
// //Option to delete existing data for full reset | ||
// Option to delete existing data for full reset | ||
// await User.deleteMany({}) | ||
|
||
let user3 = new User({ | ||
firstname: "Rebecca", | ||
lastname: "Albright" | ||
// await Goal.deleteMany({}) | ||
|
||
let goal1 = new Goal({ | ||
goalId: "G10001", | ||
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 user1 = new User({ | ||
userId: "U10001", | ||
email: "[email protected]", | ||
passwordHashed: "pa55w0rd", | ||
name: "John Smith", | ||
createdAt: "2024-09-01", | ||
goals: [goal1] | ||
}) | ||
let user4 = new User({ | ||
firstname: "James", | ||
lastname: "Madison" | ||
|
||
let user2 = new User({ | ||
userId: "U10002", | ||
email: "[email protected]", | ||
passwordHashed: "b0st0nuniversity", | ||
name: "Jane Doe", | ||
// createdAt: "2024-09-01", // testing the default param in schema works | ||
goals: [] | ||
}) | ||
|
||
await Promise.all([ | ||
user3.save(), | ||
user4.save() | ||
user1.save(), | ||
user2.save(), | ||
goal1.save() | ||
]) | ||
|
||
let users = await User.find({}) | ||
|
||
console.log(users) | ||
|
||
} catch(error) { | ||
let goals = await Goal.find({}) | ||
console.log(goals) | ||
|
||
} catch(error) { | ||
console.log(error) | ||
|
||
} finally { | ||
|
||
db.closeConnection() | ||
|
||
} | ||
} | ||
|
||
|