From c57d8a01baa22a7ea8e2b29c8e4a395509707c9a Mon Sep 17 00:00:00 2001 From: Ashelyn Dawn Date: Sat, 5 Jun 2021 23:14:04 -0600 Subject: [PATCH] Fix issue where all sessions were being interpreted as users --- import/index.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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()