forked from mitchdmarino/InCRUDibles-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbTest.js
70 lines (58 loc) · 1.49 KB
/
dbTest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const db = require('./models')
// testing user CREATE
db.Account.create({
name: 'First Account',
email: '[email protected]',
password: '1234'
})
.then(account => {
console.log('Did this work? ', account)
})
.catch(console.warn)
const addProfile = async () => {
// find the account
const account = await db.Account.findOne({email:'[email protected]'})
console.log(account)
// create a new profile
const newProfile = await db.Profile.create({
name: '2'
})
// Add the
account.profiles.push(newProfile)
// save
await account.save()
await newProfile.save()
console.log(account)
}
addProfile()
const addTask = async () => {
// find the account
const account = await db.Account.findOne({email:'[email protected]'})
console.log(account)
// create a new Task
const newTask = await db.Task.create({
description: 'new Task',
completed: false
})
// Add the
account.tasks.push(newTask)
// save
await account.save()
await newTask.save()
console.log(account)
}
addTask()
// completing a task
const completeTask = async () => {
// find the Task
const task = await db.Task.findById('62b5ee14467063340369091d')
// task completed
task.completed = true
// find the profile
const profile = await db.Profile.findById('62b5edf5039e050bad0a78d1')
console.log(profile)
task.profile = profile
task.save()
console.log(task)
}
completeTask()