Last active
October 20, 2016 18:38
-
-
Save dabit3/e41fb641bddbf27cbf22d8258645c7f5 to your computer and use it in GitHub Desktop.
Apollo Tutorial - Seed
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 request = require('request-promise'); | |
const President = require('./model'); | |
const seed = () => { | |
request('https://mysafeinfo.com/api/data?list=presidents&format=json') | |
.then(res => JSON.parse(res)) | |
.then((res) => { | |
const data = res.map((r) => { | |
const obj = {}; | |
obj.name = r.nm; | |
obj.party = r.pp; | |
obj.term = r.tm; | |
return obj; | |
}); | |
data.forEach((d) => { | |
const president = new President(d); | |
president.save((err, item) => { | |
console.log('saved:', item); | |
}); | |
}); | |
}) | |
.catch((err) => { | |
console.log('err:', err); | |
}); | |
}; | |
module.exports = seed; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment