@@ -8,7 +8,6 @@ import app from './app';
8
8
mongoose . connect ( 'mongodb://localhost:27017/which' , { useNewUrlParser : true } ) ;
9
9
10
10
const POLLS_AMOUNT = 20 ;
11
- const VOTES_AMOUNT = 160 ;
12
11
13
12
const imageUrls : string [ ] = [
14
13
// eslint-disable max-len
@@ -59,10 +58,9 @@ const createUser = (username: string): Promise<User> => {
59
58
60
59
const createVote = ( userId : string , pollId : string ) : Promise < Vote > => {
61
60
return app . service ( 'votes' ) . create ( {
62
- userId,
63
61
pollId,
64
62
which : _ . sample ( choices )
65
- } ) ;
63
+ } , { user : { _id : userId } } ) ;
66
64
}
67
65
68
66
@@ -72,13 +70,11 @@ const populate = async () => {
72
70
const polls = await bluebird . mapSeries ( new Array ( POLLS_AMOUNT ) , async ( ) => {
73
71
const user = _ . sample ( users ) ;
74
72
return createPoll ( user ?. _id || '' ) ;
75
-
76
73
} ) ;
77
74
78
- const votes = await bluebird . mapSeries ( new Array ( VOTES_AMOUNT ) , async ( ) => {
79
- const user = _ . sample ( users ) ;
80
- const poll = _ . sample ( polls ) ;
81
- return createVote ( user ?. _id || '' , poll ?. _id || '' ) ;
75
+ const votes = await bluebird . map ( users , user => {
76
+ const pollsToVote = _ . sampleSize ( polls , _ . random ( 0 , POLLS_AMOUNT ) ) ;
77
+ return bluebird . map ( pollsToVote , poll => createVote ( user ?. _id || '' , poll ?. _id || '' ) ) ;
82
78
} ) ;
83
79
} ;
84
80
0 commit comments