Last active
June 19, 2020 21:15
-
-
Save xApnea/9048bed7d5f79bb79df403b1c3f74876 to your computer and use it in GitHub Desktop.
This file contains 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 faker = require('faker'); | |
const db = require('./index.js'); | |
const Product = require('./model.js'); | |
const numOfDataPoints = 10; | |
var generateEntry = function(numOfVariations) { | |
var randomTitle = faker.commerce.productName(); //Fender Stratocaster | |
var randomDescription = faker.lorem.paragraph(); | |
var variations = []; | |
for (var i = 0; i < numOfVariations; i++) { | |
var randomColor = faker.commerce.color(); // black | |
var randomCost = faker.commerce.price(); // 492.00 | |
var randomImages = [ | |
{src: faker.image.imageUrl(846, 1038)}, | |
{src: faker.image.imageUrl(846, 1038)}, | |
{src: faker.image.imageUrl(846, 1038)}, | |
{src: faker.image.imageUrl(846, 1038)} | |
] // 4 random image urls | |
var variation = { | |
color: randomColor, | |
cost: randomCost, | |
images: randomImages | |
} | |
variations.push(variation); | |
} | |
var entry = { | |
title: randomTitle, | |
description: randomDescription, | |
variations : variations | |
} | |
return entry; | |
} | |
var seedDatabase = function() { | |
var sampleData = []; | |
for (var i = 0; i < numOfDataPoints; i++) { | |
var numOfVariations = Math.ceil((Math.random() * 4)); | |
sampleData.push(generateEntry(numOfVariations)); | |
} | |
Product.create(sampleData) | |
.then(() => db.disconnect()); | |
} | |
seedDatabase(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment