-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed.js
121 lines (107 loc) · 6.13 KB
/
seed.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import mongoose from 'mongoose'
// import crypto from 'crypto'
import Product from './src/server/model/product'
import Item from './src/server/model/item'
import User from './src/server/model/user'
import Manufacturer from './src/server/model/manufacturer'
mongoose.connect('mongodb://heroku_hmbt50dq:[email protected]:31258/heroku_hmbt50dq')
/* eslint-disable */
const products = [{"name":"Supreme x The North Face Leopard Nuptse","description":"Ideal for unpredictable weather forecasts, this packable, warm jacket is crafted from more than 50% recycled content and insulated with 700 fill down that’s certified to the Responsible Down Standard (RDS).","retailer":"Supreme","image":"https://i.imgur.com/fqQ2Bfs.jpg"},
{"name":"Rolex Submariner","description":"The Rolex Submariner’s robust and functional design swiftly became iconic. With their subtly redesigned Oyster case, distinctive dial with large luminescent hour markers, graduated rotatable Cerachrom bezel and solid link Oyster bracelet, the latest generation Submariner and Submariner Date are firmly in line with the original model launched in 1953.","retailer":"Rolex","image":"https://cdn2.jomashop.com/media/catalog/product/r/o/rolex-oyster-perpetual-submariner-black-dial-black-cerachrom-bezel-steel-mens-watch-116610ln.jpg"},
{"name":"iPhone X","description":"Our vision has always been to create an iPhone that is entirely screen. One so immersive the device itself disappears into the experience. And so intelligent it can respond to a tap, your voice, and even a glance. With iPhone X, that vision is now a reality. Say hello to the future.","retailer":"Apple","image":"https://onetechmind.com/content/images/iphonex-hero.png"},
{"name":"Palm Springs Backpack Mini","description":"Nicolas Ghesquière gave a surprising twist to the backpack, turning a utilitarian staple into this trendy and oh-so-covetable city bag. The sweet Mini version in soft Monogram canvas sports a multi-positional strap for cross-body wear.","retailer":"Loius Vuitton","image":"https://wbcdn.worldsbest.com/uploads/35/29063/1497538845.jpg"},
{"name":"Rembrandt Oil on Canvas Painting","description":"School of Rembrandt Harmensz. van Rijn. circa 1650, A kitchen interior and a woman plucking a chicken with a copper pot, baskets and a plate of fish, oil on canvas","retailer":"Sotheby's","image":"https://i.pinimg.com/564x/ed/b5/38/edb53802ec7488fc99383654a284a886.jpg"},
{"name":"Cartier Gold Half Diamond Love Bracelet","description":"Love bracelet, 18K yellow gold.","retailer":"Cartier","image":"http://www.raymondleejewelers.net/wp-content/uploads/2014/12/Cartier-18K-Yellow-Gold-Love-Diamond-Bangle-Bracelet-1024x1024.jpg"},
{"name":"Sainte Paul","description":"utilize interactive users","retailer":"Schaefer, Schmeler and Price","image":"http://dummyimage.com/209x114.png/dddddd/000000"},
{"name":"Iacobucci","description":"engineer e-business deliverables","retailer":"Cartwright, Lynch and Schulist","image":"http://dummyimage.com/169x240.bmp/5fa2dd/ffffff"},
{"name":"Ewbanke","description":"redefine B2C e-commerce","retailer":"Heaney LLC","image":"http://dummyimage.com/100x110.png/5fa2dd/ffffff"},
{"name":"Meldrum","description":"whiteboard web-enabled deliverables","retailer":"Runolfsson, Spinka and Lemke","image":"http://dummyimage.com/117x191.jpg/cc0000/ffffff"}]
/* eslint-enable */
const user = {
full_name: 'Jeremy Odell',
email: '[email protected]',
password: '$2a$10$is/Zb98l9UYf8wzYWMdk5epyn5hoXlwxg48Qjqpg9bkOgyQ0BFCw.', // 'qwerqwer'
isVerified: true,
}
const userTwo = {
full_name: 'Azhar Hussain',
email: '[email protected]',
password: '$2a$10$is/Zb98l9UYf8wzYWMdk5epyn5hoXlwxg48Qjqpg9bkOgyQ0BFCw.', // 'qwerqwer'
isVerified: true,
}
const manu = {
name: 'Nordstrom',
email: '[email protected]',
password: '$2a$10$is/Zb98l9UYf8wzYWMdk5epyn5hoXlwxg48Qjqpg9bkOgyQ0BFCw.', // 'qwerqwer'
isVerified: true,
}
const manuTwo = {
name: 'Rolex',
email: '[email protected]',
password: '$2a$10$is/Zb98l9UYf8wzYWMdk5epyn5hoXlwxg48Qjqpg9bkOgyQ0BFCw.', // 'qwerqwer'
isVerified: true,
}
const promises = []
new User(user).save()
.then(usr => Promise.all([new Product(products[0]).save(), usr]))
.then((res) => {
const m = new Item({ serial: 0, product: res[0]._id, cora_id: '12304321' }).save()
promises.push(m)
return Promise.all(promises)
})
.then(usr => Promise.all([new Product(products[1]).save(), usr]))
.then((res) => {
const m = new Item({ serial: 1, product: res[0]._id, cora_id: '12314321' }).save()
promises.push(m)
return Promise.all(promises)
})
.then(usr => Promise.all([new Product(products[2]).save(), usr]))
.then((res) => {
const m = new Item({ serial: 2, product: res[0]._id, cora_id: '12324321' }).save()
promises.push(m)
return Promise.all(promises)
})
.then(usr => Promise.all([new Product(products[3]).save(), usr]))
.then((res) => {
const m = new Item({ serial: 3, product: res[0]._id, cora_id: '12334321' }).save()
promises.push(m)
return Promise.all(promises)
})
.then(usr => Promise.all([new Product(products[4]).save(), usr]))
.then((res) => {
const m = new Item({ serial: 4, product: res[0]._id, cora_id: '12344321' }).save()
promises.push(m)
return Promise.all(promises)
})
.then(usr => Promise.all([new Product(products[5]).save(), usr]))
.then((res) => {
const m = new Item({ serial: 5, product: res[0]._id, cora_id: '12354321' }).save()
promises.push(m)
return Promise.all(promises)
})
.then((res) => {
User.update(
{ full_name: 'Jeremy Odell' },
{ $push: { ownership: { $each: res } } },
).exec()
})
.then(new User(userTwo).save())
.then(new Manufacturer(manu).save())
.then(new Manufacturer(manuTwo).save())
.then(() => {
const Rolex = Manufacturer.findOne({ name: 'Rolex' })
const watch = Product.findOne({ name: 'Rolex Submariner' })
return Promise.all([Rolex, watch])
})
.then(([RolexRes, watchRes]) => {
RolexRes.productLines.push(watchRes)
RolexRes.markModified('ownership')
return RolexRes.save()
})
.then(() => mongoose.disconnect())
.catch(console.log)
// Make fake user
// Loop thru products
// save product,
// then make item with (serial: randInt, product: product._id, cora_id: randHash)
// then push item to fake user inventory