-
Notifications
You must be signed in to change notification settings - Fork 7
/
seed.js
144 lines (127 loc) · 2.8 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**
* Populate DB with sample data on server start
* to disable, edit .env, and remove `SEED_DB`
*/
'use strict';
var Settings = require('./models/settings.js');
var Consumer = require('./models/consumer.js');
var User = require('./models/users.js');
var Vehicle = require('./models/vehicle.js');
var Directions = require('./models/directions.js');
var async = require('async');
async.series([
function(callback) {
seedSettings(function() {
callback();
});
},
function(callback) {
seedConsumers(function() {
callback();
});
},
function(callback) {
seedVehicles(function() {
callback();
});
}
]);
/**
* CONSUMERS
*
* model:
name: {type: String, required: true},
sex: {type: String, required: true, enum:['male', 'female']},
address: {type: String, required: true},
phone: String,
// Details flags
needsWave: Boolean,
behavioralIssues: Boolean,
needsTwoSeats: Boolean,
hasSeizures: Boolean,
hasWheelchair: Boolean,
hasMedications: Boolean
*/
var consumerSeed = require('./consumers');
function seedConsumers(done) {
consumerSeed.push(function() {
done()
console.log('finished populating consumers');
}
)
Consumer.find({}).remove(function() {
Consumer.create.apply(Consumer, consumerSeed);
});
}
/**
* VEHICLES
*
* model:
name: {type: String, required: true},
seats: {type:Number, required:true},
flexSeats: {type:Number, default:0},
wheelchairs: {type:Number, default: 0},
consumers: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Consumer',
}]
*/
var vehicleSeed = require('./vehicles');
function seedVehicles(done) {
vehicleSeed.push(function() {
done();
console.log('finished populating vehicles');
}
)
Vehicle.find({}).remove(function() {
// Consumers pre-population can be done here...
Vehicle.create.apply(Vehicle,vehicleSeed);
});
}
/**
* SETTINGS
*/
function seedSettings(done) {
Settings.find({}).remove(function() {
Settings.create({
optionsIncAddress: '16820 197th Ave NW, Big Lake, MN 55309',
optionsIncCoords: {
lat: 45.3292957,
lng: -93.69755090000001
},
maxPassengersPerVehicle: 14,
maxConsumerRouteTime: 90,
routeStopWaitTime: 3
}, function() {
console.log('finished populating settings');
done();
});
});
}
/**
* USERS
*/
User.find({}).remove(function() {
User.create({
email: '[email protected]',
password: '12345',
role: 'user'
}, {
email: '[email protected]',
password: 'admin',
role: 'admin'
}, {
email: '[email protected]',
password: 'asdf',
role: 'admin'
}, function() {
console.log('finished populating users');
});
});
/**
* Directions
*
*/
Directions.find({}).remove(function() {
console.log('finished populating directions');
});