1
1
import mongoose from 'mongoose' ;
2
2
import Promise from 'bluebird' ;
3
+ import _ from 'lodash' ;
3
4
import app from './app' ;
5
+ import { UserSchema } from './models/users/user.schema' ;
4
6
5
7
mongoose . connect ( 'mongodb://localhost:27017/which' , { useNewUrlParser : true } ) ;
6
8
@@ -17,8 +19,40 @@ const users = [
17
19
{ name : "Ethan" } ,
18
20
] ;
19
21
20
- Promise . map ( users , async user => {
21
- return await app . service ( 'users' ) . create ( user ) ;
22
- } ) . catch ( e => console . error ( e ) )
23
- . finally ( ( ) => mongoose . disconnect ( ) ) ;
22
+ const polls = [ {
23
+ contents : {
24
+ left :{
25
+ url : 'https://cdn.psychologytoday.com/sites/default/files/field_blog_entry_images/2019-06/pexels-photo-556667.jpeg' ,
26
+ votes : 0
27
+ } ,
28
+ right :{
29
+ url : 'https://images.pexels.com/photos/556666/pexels-photo-556666.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500' ,
30
+ votes : 0
31
+ }
32
+ }
33
+ } , {
34
+ contents : {
35
+ left :{
36
+ url : 'https://cdn.psychologytoday.com/sites/default/files/field_blog_entry_images/2019-06/pexels-photo-556667.jpeg' ,
37
+ votes : 0
38
+ } ,
39
+ right :{
40
+ url : 'https://images.pexels.com/photos/556666/pexels-photo-556666.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500' ,
41
+ votes : 0
42
+ }
43
+ }
44
+ } ] ;
24
45
46
+ const populate = async ( ) => {
47
+ const createdUsers = await Promise . map ( users , async user => {
48
+ return await app . service ( 'users' ) . create ( user ) ;
49
+ } ) ;
50
+ console . log ( createdUsers ) ;
51
+ await Promise . map ( polls , async poll => {
52
+ const user = _ . sample ( createdUsers ) ;
53
+ return await app . service ( 'polls' ) . create ( { ...poll , authorId : user . _id } ) ;
54
+ } ) ;
55
+ mongoose . disconnect ( ) ;
56
+ } ;
57
+
58
+ populate ( ) ;
0 commit comments