Created
June 17, 2020 12:35
-
-
Save kianaditya/1ef1621e8a5205c367e0888b5fb2faee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const db = require('../index') | |
const chance = require('chance').Chance() | |
const faker = require('faker') | |
const createSeeds = async () => { | |
const author1 = await db.User.create({ | |
firstName: chance.first(), | |
lastName: chance.last(), | |
}) | |
const author2 = await db.User.create({ | |
firstName: faker.name.firstName(), | |
lastName: faker.name.lastName(), | |
}) | |
const postsCount = 3 | |
chance.mixin({ | |
post: function () { | |
return { | |
title: chance.sentence({ words: 5 }), | |
content: chance.sentence({ words: 15 }), | |
} | |
}, | |
}) | |
for (let index = 0; index < postsCount; index++) { | |
const post = await db.Post.create(chance.post()) | |
author1.addAuthor(post) | |
} | |
for (let index = 0; index < postsCount; index++) { | |
const post = await db.Post.create({ | |
title: faker.lorem.sentence(), | |
content: faker.lorem.sentence(), | |
}) | |
author2.addAuthor(post) | |
} | |
} | |
module.exports = createSeeds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment