diff --git a/import/index.js b/import/index.js index c331825..0e14c51 100644 --- a/import/index.js +++ b/import/index.js @@ -13,14 +13,16 @@ const saveExcelDataFile = require('./tasks/writeExcelSheet') async function doMigration() { const items = await oldDB.sock.find().lean().exec() - const users = await oldDB.user.find().populate('purchases').lean().exec() - const carts = users.map(u => u.purchases).flat() + const allUsers = await oldDB.user.find().populate('purchases').lean().exec() + const carts = allUsers.map(u => u.purchases).flat() const coupons = await oldDB.coupon.find().lean().exec() - console.log(`Loaded ${carts.length} purchases from ${users.length} users`) + const registeredUsers = allUsers.filter(user => user.email) - console.log(`Inserting ${users.length} users into the database`) - const importAdmin = await createUsers(newDB, users); + console.log(`Loaded ${carts.length} purchases and ${registeredUsers.length} users`) + + console.log(`Inserting ${registeredUsers.length} users into the database`) + const importAdmin = await createUsers(newDB, registeredUsers); console.log(` Found user account ${importAdmin.uuid} (${importAdmin.email}) to attribute file uploads to`) console.log(`\nInserting ${items.length} items into database`) @@ -31,7 +33,7 @@ async function doMigration() { await uploadImages(newDB, itemImages, importAdmin.uuid) console.log('\nWriting Excel data file') - await saveExcelDataFile(users, coupons, items, path.join(__dirname, './datafile.xlsx')) + await saveExcelDataFile(allUsers, coupons, items, path.join(__dirname, './datafile.xlsx')) } doMigration()