{"size": 1623, "ext": "js", "max_stars_repo_path": "seed/product-seeder.js", "max_stars_repo_name": "mscoobby/webshop-boilerplate-api", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "seed/product-seeder.js", "max_issues_repo_name": "mscoobby/webshop-boilerplate-api", "max_issues_repo_issues_event_min_datetime": "2017-07-22T10:41:58.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-03T06:25:31.000Z", "max_forks_repo_path": "seed/product-seeder.js", "max_forks_repo_name": "mscoobby/webshop-boilerplate-api", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 5, "max_forks_count": null, "avg_line_length": 31.8235294118, "max_line_length": 130, "alphanum_fraction": 0.5982747998}
const mongoose = require('mongoose');
const chalk = require('chalk');

const Product = require('../models/Product')

mongoose.Promise = global.Promise;
mongoose.connect('mongodb://127.0.0.1:27017/test', {
    useMongoClient: true
});
mongoose.connection.on('error', (err) => {
    console.error(err);
    console.log('%s MongoDB connection error. Please make sure MongoDB is running.', chalk.red('✗'));
    process.exit();
});

let products = [new Product({
    imagePaths: ['http://via.placeholder.com/250x200', 'http://via.placeholder.com/200x150', 'http://via.placeholder.com/350x250']
    , title: 'Product'
    , price: 9.99
    , description: 'This is awesome product'
    , sizes: [1, 2, 3, 4]
    , colors: ['black', 'gray']
}), new Product({
    imagePaths: ['http://via.placeholder.com/250x200', 'http://via.placeholder.com/200x150', 'http://via.placeholder.com/350x250']
    , title: 'Product'
    , price: 9.99
    , description: 'This is awesome product'
    , sizes: [1, 2, 3, 4]
    , colors: ['black', 'gray']
}), new Product({
    imagePaths: ['http://via.placeholder.com/250x200', 'http://via.placeholder.com/200x150', 'http://via.placeholder.com/350x250']
    , title: 'Product'
    , price: 9.99
    , description: 'This is awesome product'
    , sizes: [1, 2, 3, 4]
    , colors: ['black', 'gray']
})]

let done = 0;

for (var i = 0; i < products.length; i++) {
    products[i].save()
        .then(r => {
            done++;
            if (done === products.length) mongoose.disconnect()
        })
        .catch(error => {
            console.error('%s Error' + error, chalk.red('✗'))
        })
}
