Created
June 29, 2019 22:33
-
-
Save obrien-k/01874b2a6e1ce45cf986eb0ed0438001 to your computer and use it in GitHub Desktop.
wishlists function
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 getWishlists = new Promise(async function(resolve, reject) { | |
await bigCommerce.get('/wishlists').then(data => { | |
Arr = data.data; | |
let wArr = []; | |
for (let [key, value] of Object.entries(Arr)) { | |
if (value.id) { | |
wArr.push(value.id); | |
} | |
} | |
e(); | |
async function e(resolve) { | |
for (i = 0; i < wArr.length; i++) { | |
await bigCommerce.get('/wishlists/' + wArr[i]).then(data => { | |
wishlistsArr = []; | |
wishlistsArr = data.data; | |
console.log(wishlistsArr.id + 'LINE 148'); | |
Wishlist.collection.findOne({ id: wishlistsArr.id }, null, function( | |
err, | |
docs | |
) { | |
if (docs === null) { | |
Wishlist.collection.insertOne(data.data, function(err, res) { | |
if (err) throw err; | |
console.log( | |
'Number of documents inserted: ' + res.insertedCount | |
); | |
}); | |
if (err) throw err; | |
} else { | |
reject(err); | |
} | |
}); | |
}); | |
} | |
} | |
return resolve(); | |
}); | |
}).catch(err => { | |
console.log('getWishlists rejected' + err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment