Skip to content

Instantly share code, notes, and snippets.

@kianaditya
Created June 18, 2020 09:04
Show Gist options
  • Save kianaditya/f287485415fc8850a1ba0ea3e38d0028 to your computer and use it in GitHub Desktop.
Save kianaditya/f287485415fc8850a1ba0ea3e38d0028 to your computer and use it in GitHub Desktop.
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(),
email: '[email protected]',
encryptedPassword: 'password',
})
const author2 = await db.User.create({
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
email: '[email protected]',
encryptedPassword: 'password',
})
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)
}
}
const deleteSeeds = async () => {
await db.User.destroy
await db.Post.destroy
}
module.exports = {createSeeds, deleteSeeds}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment