-
Notifications
You must be signed in to change notification settings - Fork 0
/
datafeed.js
81 lines (71 loc) · 2.03 KB
/
datafeed.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
70
71
72
73
74
75
76
77
78
79
80
81
require('dotenv').config()
import 'babel-polyfill'
import mongoose from 'mongoose'
mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true })
import User from './models/user'
import Review from './models/review'
const users = [
{
"firstName": "Kannan",
"lastName": "Ganesan",
"email": "kannan@coder.com",
"password": "$2b$08$scEV5n6CcvRJS0RhMyFEn.PuxtSX311P5CDx86.qyCWzNicGqTbDu",
"type": "admin"
},
{
"firstName": "Priya",
"lastName": "Promodharshini",
"email": "priya@coder.com",
"password": "$2b$08$scEV5n6CcvRJS0RhMyFEn.PuxtSX311P5CDx86.qyCWzNicGqTbDu",
"type": "employee"
},
{
"firstName": "Hossian",
"lastName": "J",
"email": "hossian@coder.com",
"password": "$2b$08$scEV5n6CcvRJS0RhMyFEn.PuxtSX311P5CDx86.qyCWzNicGqTbDu",
"type": "employee"
},
{
"firstName": "Saatvika",
"lastName": "Kannan",
"email": "saatvika@coder.com",
"password": "$2b$08$scEV5n6CcvRJS0RhMyFEn.PuxtSX311P5CDx86.qyCWzNicGqTbDu",
"type": "employee"
}
]
async function RunMigrations() {
// Delete users and reviews
await User.remove({})
await Review.remove({})
// Add users
const UserPromises = users.map(e => User.create(e))
const usersList = await Promise.all(UserPromises)
console.log('Users have been added sucessfully!')
// Adding reviews
const reviews = [
{
author: usersList[0]._id.toString(),
target: usersList[1]._id.toString(),
body: 'Review for user 1',
participants: [
{ author: usersList[0]._id.toString() },
{ author: usersList[2]._id.toString() }
]
},
{
author: usersList[0]._id.toString(),
target: usersList[2]._id.toString(),
body: 'Review for user 1',
participants: [
{ author: usersList[1]._id.toString() },
{ author: usersList[3]._id.toString() }
]
},
]
const ReviewPromises = reviews.map(e => Review.create(e))
await Promise.all(ReviewPromises)
console.log('Reviews have been added sucessfully!')
process.exit(0)
}
RunMigrations()