@@ -29,6 +29,7 @@ const Notification = models.Notification;
29
29
const Service = models . Service ;
30
30
const DronePosition = models . DronePosition ;
31
31
const NoFlyZone = models . NoFlyZone ;
32
+ const Question = models . Question ;
32
33
33
34
let drones ;
34
35
if ( process . argv [ 2 ] === 'drones-within-area' ) {
@@ -47,6 +48,7 @@ const notifications = require('./data/notifications.json');
47
48
const providerUsers = require ( './data/provider-users.json' ) ;
48
49
const positions = require ( './data/dronePositions.json' ) ;
49
50
const noFlyZones = require ( './data/no-fly-zones.json' ) ;
51
+ const questions = require ( './data/questions.json' ) ;
50
52
51
53
const MissionStatus = require ( './enum' ) . MissionStatus ;
52
54
const RequestStatus = require ( './enum' ) . RequestStatus ;
@@ -74,6 +76,7 @@ co(function*() {
74
76
yield Notification . remove ( { } ) ;
75
77
yield DronePosition . remove ( { } ) ;
76
78
yield NoFlyZone . remove ( { } ) ;
79
+ yield Question . remove ( { } ) ;
77
80
78
81
// encrypt password
79
82
yield _ . map ( users , ( u ) => function * ( ) {
@@ -147,7 +150,7 @@ co(function*() {
147
150
148
151
_ . each ( missions , ( m , i ) => {
149
152
m . provider = packageDocs [ i % packageDocs . length ] . provider ;
150
- m . pilot = userDocs [ 0 ] . id ; // setting all to first user for testing convinience
153
+ m . pilot = userDocs [ 0 ] . id ; // setting all to first user for testing convenience
151
154
m . drone = droneDocs [ i % droneDocs . length ] . id ;
152
155
m . status = _ . values ( MissionStatus ) [ Math . floor ( Math . random ( ) * _ . values ( MissionStatus ) . length ) ] ;
153
156
m . telemetry = {
@@ -166,18 +169,20 @@ co(function*() {
166
169
} ] ;
167
170
} ) ;
168
171
logger . info ( `creating ${ missions . length } missions` ) ;
169
- const missionDocs = yield Mission . create ( missions ) ;
172
+ const missionDocs = yield Mission . create (
173
+ _ . map ( missions , ( mission , index ) => _ . assign ( mission , { missionName : mission . missionName + ' ' + index } ) )
174
+ ) ;
170
175
171
176
_ . each ( reviews , ( r , i ) => {
172
- r . user = userDocs [ 0 ] . id ; // setting all to first user for testing convinience
177
+ r . user = userDocs [ 0 ] . id ; // setting all to first user for testing convenience
173
178
r . mission = missionDocs [ i % missionDocs . length ] . id ;
174
179
r . provider = missionDocs [ i % missionDocs . length ] . provider ;
175
180
} ) ;
176
181
logger . info ( `creating ${ reviews . length } reviews` ) ;
177
182
yield Review . create ( reviews ) ;
178
183
179
184
_ . each ( requests , ( r , i ) => {
180
- r . user = userDocs [ 0 ] . id ; // setting all to first user for testing convinience
185
+ r . user = userDocs [ 0 ] . id ; // setting all to first user for testing convenience
181
186
r . package = packageDocs [ i % packageDocs . length ] . id ;
182
187
r . provider = packageDocs [ i % packageDocs . length ] . provider ;
183
188
} ) ;
@@ -205,8 +210,16 @@ co(function*() {
205
210
const mindex = i % missionDocs . length ;
206
211
missionDocs [ mindex ] . packageRequest = requestDocs [ i ] . id ;
207
212
missionDocs [ mindex ] . provider = requestDocs [ i ] . provider ;
208
- missionDocs [ mindex ] . status = i % 2 ? MissionStatus . IN_PROGRESS : MissionStatus . COMPLETED ;
209
- missionDocs [ mindex ] . pilot = providerUserDocs [ i % providerDocs . length ] . id ;
213
+ // add some missions to the pilot user
214
+ if ( i % ( providerDocs . length + 1 ) !== providerDocs . length ) {
215
+ missionDocs [ mindex ] . pilot = providerUserDocs [ i % ( providerDocs . length + 1 ) ] . id ;
216
+ // for provider user use same statuses as for providerRequests
217
+ missionDocs [ mindex ] . status = i % 2 ? MissionStatus . IN_PROGRESS : MissionStatus . COMPLETED ;
218
+ } else {
219
+ missionDocs [ mindex ] . pilot = userDocs [ 2 ] . id ; // pilot user
220
+ // for pilot user use all possible statuses
221
+ missionDocs [ mindex ] . status = MissionStatus [ _ . keys ( MissionStatus ) [ Math . floor ( _ . keys ( MissionStatus ) . length * Math . random ( ) ) ] ] ;
222
+ }
210
223
missionDocs [ mindex ] . scheduledAt = today . add ( 1 , 'h' ) . toDate ( ) ; // +1 hour
211
224
missionDocs [ mindex ] . startedAt = today . add ( 2 , 'h' ) . toDate ( ) ; // +2 hours
212
225
missionDocs [ mindex ] . launchDate = today . toDate ( ) ;
@@ -218,7 +231,7 @@ co(function*() {
218
231
yield missionDocs [ mindex ] . save ( ) ;
219
232
}
220
233
_ . each ( notifications , ( n ) => {
221
- n . user = userDocs [ 0 ] . id ; // setting all to first user for testing convinience
234
+ n . user = userDocs [ 0 ] . id ; // setting all to first user for testing convenience
222
235
} ) ;
223
236
logger . info ( `creating ${ notifications . length } notifications` ) ;
224
237
yield Notification . create ( notifications ) ;
@@ -232,6 +245,9 @@ co(function*() {
232
245
logger . info ( `creating ${ noFlyZones . length } no fly zones` ) ;
233
246
yield NoFlyZone . create ( noFlyZones ) ;
234
247
248
+ logger . info ( `creating ${ questions . length } questions` ) ;
249
+ const questionDocs = yield Question . create ( questions ) ;
250
+
235
251
logger . info ( 'data created successfully' ) ;
236
252
} ) . then ( ( ) => {
237
253
logger . info ( 'Done' ) ;
0 commit comments