Skip to content

Commit

Permalink
fix(import): importing users with csv #418
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Jul 12, 2021
1 parent 26fccc9 commit d2cab62
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/controllers/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ accountsController.uploadCSV = function (req, res) {
})

var object = {}
var parser = csv()

var parser = csv.parse()

busboy.on('file', function (fieldname, file) {
object.csv = []

Expand All @@ -309,11 +311,13 @@ accountsController.uploadCSV = function (req, res) {
})

parser
.on('readable', function () {
var data
while ((data = parser.read()) !== null) {
object.csv.push(data)
}
.on('data', function (row) {
object.csv.push(row)
// var data
// while ((data = parser.read()) !== null) {
// console.log(data)
// object.csv.push(data)
// }
})
.on('end', function () {
if (object.csv.length < 1) {
Expand All @@ -325,7 +329,7 @@ accountsController.uploadCSV = function (req, res) {
return i.toLowerCase() === 'username'
})
var fullnameIdx = _.findIndex(titleRow, function (i) {
return i.toLowerCase() === 'fullname'
return i.toLowerCase() === 'name'
})
var emailIdx = _.findIndex(titleRow, function (i) {
return i.toLowerCase() === 'email'
Expand All @@ -334,7 +338,7 @@ accountsController.uploadCSV = function (req, res) {
return i.toLowerCase() === 'title'
})
var roleIdx = _.findIndex(titleRow, function (i) {
return i.toLowerCase() === 'role'
return i.toLowerCase() === 'roleid'
})

object.csv.splice(0, 1)
Expand Down

0 comments on commit d2cab62

Please sign in to comment.