This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
SA3/hw6/Claudio_Maggioni/test/seed.js

47 lines
965 B
JavaScript
Raw Normal View History

2019-10-28 14:00:36 +00:00
'use strict';
var config = require('../config');
var request = require('request');
//seedData
var seedData = require('./seedData')
//total callbacks (one for each model)
var totalCbs = 0;
var cbCnt = 0;
/**
* Recursive function that goes through
* seedData populating each item of it
*/
var seedModel = function(done, s){
if(s != undefined) {
seedData = s
}
totalCbs = seedData.length
for (let i = 0; i < seedData.length; i++) {
const form = {}
form[config.form._id] = seedData[i]._id
form[config.form.name] = seedData[i].name
form[config.form.dataURL] = seedData[i].dataURL
form[config.form.bookmarked] = seedData[i].bookmarked
request.post(`${config.url}/favorites`, {
form: form
}, function(error, response, body){
cbCnt++
if(cbCnt == totalCbs) {
done(seedData)
}
})
}
}
/**
* This is where everything starts
*/
module.exports.seed = function (done, s){
seedModel(done, s)
}