diff options
Diffstat (limited to 'populateDb.ts')
-rw-r--r-- | populateDb.ts | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/populateDb.ts b/populateDb.ts index 6f5beaf..732cb51 100644 --- a/populateDb.ts +++ b/populateDb.ts @@ -1,6 +1,8 @@ import mongoose from 'mongoose'; import Promise from 'bluebird'; +import _ from 'lodash'; import app from './app'; +import { UserSchema } from './models/users/user.schema'; mongoose.connect('mongodb://localhost:27017/which', { useNewUrlParser: true }); @@ -17,8 +19,40 @@ const users = [ { name: "Ethan" }, ]; -Promise.map(users, async user => { - return await app.service('users').create(user); -}).catch(e => console.error(e)) - .finally(() => mongoose.disconnect()); +const polls = [{ + contents: { + left:{ + url: 'https://cdn.psychologytoday.com/sites/default/files/field_blog_entry_images/2019-06/pexels-photo-556667.jpeg', + votes: 0 + }, + right:{ + url: 'https://images.pexels.com/photos/556666/pexels-photo-556666.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500', + votes: 0 + } + } +},{ + contents: { + left:{ + url: 'https://cdn.psychologytoday.com/sites/default/files/field_blog_entry_images/2019-06/pexels-photo-556667.jpeg', + votes: 0 + }, + right:{ + url: 'https://images.pexels.com/photos/556666/pexels-photo-556666.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500', + votes: 0 + } + } +}]; +const populate = async () => { + const createdUsers = await Promise.map(users, async user => { + return await app.service('users').create(user); + }); + console.log(createdUsers); + await Promise.map(polls, async poll => { + const user = _.sample(createdUsers); + return await app.service('polls').create({...poll, authorId: user._id}); + }); + mongoose.disconnect(); +}; + +populate();
\ No newline at end of file |