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
|
'use strict';
const app = require('../src/app')
const dish = require('./dish')
const User = app.service('users')
const Meal = app.service('meals')
console.log('hey')
User.create({
email: 'admin@toptal',
password: 'admin',
role: 'admin',
goal: 5000,
}).then((user) => {
let userid = user.id
populateMeals(userid)
})
User.create({
email: 'manager@toptal',
password: 'manager',
role: 'manager',
goal: 3000,
}).then((user) => {
let userid = user.id
populateMeals(userid)
})
User.create({
email: 'user@toptal',
password: 'user',
role: 'user',
goal: 3000,
}).then((user) => {
let userid = user.id
populateMeals(userid)
})
function randrange(a,b){ return Math.floor((b-a) * Math.random() + a) }
function quantize(a,n){ return Math.floor(a/n)*n }
function choice(a){ return a[ Math.floor(Math.random()*a.length) ]}
function populateMeals (userid) {
console.log(userid)
for (let i = 0; i < 30; i++) {
for (let j = 0, count = randrange(3,5); j < count; j++) {
let date = new Date ()
date.setDate( date.getDate() - i )
switch (j) {
case 0:
date.setHours(randrange(6,11))
break
case 1:
date.setHours(randrange(12,15))
break
case 2:
date.setHours(randrange(17,23))
break
case 3:
date.setHours(randrange(6,23))
break
case 4:
date.setHours(randrange(0,2))
break
}
date.setMinutes(randrange(0,60))
let name = dish()
Meal.create({
name: name,
calories: quantize(randrange(500,1200), 50),
userid: userid,
date: date,
}).then(function(){
console.log(name)
})
}
}
}
|